Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Sunday, 13 April 2014

Login Page (Authentication Program) in PHP

Before reading this you must read previous article regarding php execution, which give us detail information about php execution steps, server use,etc. To read that click here.
For this we require three steps. These are as follows:-

1. HTML Page:-



First we have to write code for simple user interface. The interface must be coded in HTML. It contain at least two text boxes (username & password). Login button. And two labels. The HTML code must look like as follows.
 <form name="login" method="post" action="http://localhost/Nikhil/Connection.php">
 In the above code we see that "login" is form name. "post" is type of method to transfer data. "http://localhost/Nikhil/Connection.php" is tell us about next page to be open after pressing submit button. When we press submit button it will send all data in the page to next page. You must save this file under this directory:- "C:\wamp\www\Nikhil". We apply some logic in next page. To download HTML code click here.

HTML code
HTML code

2. PHP Code:-

When we press submit button we will diverted to Connection.php page.
mysql_connect("localhost","root","root") or die(mysql_error()) :- This code connect to MySQL database with "root" as username & password. If it fail in doing this it will print error message.
mysql_select_db("Authenticate") or die(mysql_error()) :- This code select "Authenticate" as our database on which we have to work.

$data=mysql_query("select * from Users") or die(mysql_error()) :- This code will execute required database query.
And then we apply our logic there. To find right or wrong user. You must save this file under this directory:- "C:\wamp\www\Nikhil" as Connection.php.To download php code click here.

PHP code
PHP code

3. MySQL Database:-

To download MySQL click here. We have to create MySQL database with name as "Authenticate". Create table with name "Users" under the Authenticate database. The database must look like as below:-

MySQL database 

4. Execution:-

We have to start server. then type link "http://localhost/Nikhil/Start.html" in browser. Then we see Login page. If we insert correct username & Password it will give output as below.
I. Successful Login Attempt:-

  Successful Login

II. Un Successful Login Attempt:-


 UnSuccessful Login

Hope this will help you.
Note:- This is basic tutorial only for beginners. If you want to develop website then you have to implement certain security concepts like password encryption, Session tracking, etc.



Tuesday, 25 March 2014

Creating & executing Simple php program

  • It contains FOUR steps. These are as follows.

    1.       Download WAMP server:-

    As php is server side scripting language, we require server to run php program. There are various servers available to run php program. We can use XAMPP, WAMP server. In this tutorial we are going to use WAMP server. To download WAMP server click here.


    2.       Install WAMP server:-

    You can double click on WAMP server set up file. It will start installing. Install WAMP server using default setting. By default it will install under C:\wamp directory.

    Then we have to start wamp server & then put it online. Click on the shortcut of WampServer, then wamp server automatically start. If WampServer is Offline then put it Online. It can be understood by following picture.

    Put WAMP server Online

    3.      To check WampServer Online or not:-


    Go to browser you are using. Then type http://localhost or http://127.0.0.1 . If the WampServer is active then it will show following window else it will display error message. This can be better understood from following picture.

    Show Proper working of WAMP Server

    4.       Write php Program:-

    To write php code we can use any text editor. I’m using Notepad for this. Write simple php code to display “Welcome in the World of PHP”. We write code as follows & save in C:\wamp\www directory. (If you are using XAMPP server then save php files under C:\xampp\htdocs . Rest of the process is as it is.) Save this file as Nikhil.php . Always use .php as extension to save PHP file. This can be well understood using following picture.

    How to Save PHP Program
     

    5.       Run php Page:-


    Go to Browser. In address bar type http://localhost/File_Name.php . In my case Nikhil is File_Name. Then press enter. You will see “Welcome, to the world of php”. It can be shown in following picture. 

    Output of Simple PHP Program



    Waiting for your feedback.Thanks. In next article I've explain Simple Login page in PHP using MySQL. To see this click here.