Friday, 20 April 2018

PHP Tutorial - How to Create A Simple Login Page on PHP



In the previous tutorial we discuss about how to install PHP on a windows system.  Welcome to our next tutorial, here we have explained how to create your first login page and navigate to another page. Before getting in to the tutorial, you should have a basic understanding and knowledge about the following areas:
  • HTML (Hypertext Markup Language)
  • CSS (Cascading Style Sheets)
  • JS (JavaScript)
If you want to study another topic, you will find the tutorials on W3schools.com


What is PHP?
  • PHP is an acronym for "PHP: Hypertext Preprocessor"
  • PHP is a widely-used, open source scripting language.
  • PHP scripts are executed on the server.
  • PHP is free to download and use.

PHP is Most Popular Language!

     It is powerful enough to be at the core of the biggest blogging system on the web (WordPress)!. It is deep enough to run the largest social network (Facebook)!. It is also easy enough to be a beginner's first server side language!


What is a PHP File?

  • PHP files will contain text, HTML, CSS, JavaScript, and PHP code
  • PHP code are executed on the server, and the result is returned to the browser as plain HTML
  • PHP files have extension ".php"

What Can PHP file can Do?

  • Generate dynamic page content
  • Create, open, read, write, delete, and close files on the server
  • Collect form database
  • Send and receive cookies
  • Add, delete, modify data in your database
  • Used to control user-access
  • Encrypt and decrypt data.
While running PHP file you don't have any limitation on HTML file, even you will get output as a images, PDF files, and even flash movies. You can also output any text, such as XHTML and XML.

Why PHP?
  • PHP runs on various platforms (Windows, Linux, UNIX, Mac OS X, etc.)
  • PHP is compatible with almost all servers used today (Apache, IIS, etc.)
  • PHP supports a wide range of databases
  • PHP is free.
  • PHP is easy to learn and runs efficiently on the server side.

How To Create a Simple Login Form using PHP:

  1.       First double click to run the Xampp Server
Click the start button for Apache and Mysql

                            
                       The Xampp server is started.
  •      2. Next Open the Notepad Tool

        3. You save file location Xampp/htdocs/foldername/filename.php
        4. After that code of html below
     
    Code: Login.php


    <html>
              <head>
                        <title>Simple Login Form</title>
              </head>      
              <body>
                       <form method="post" action="actions.php?emp_login=login">
                                 <table border='1' align="center">
                                          <tr>
                                                    <td>Username:</td>
                                                    <td><input type="text" name="u_name"></td>
                                          </tr>
                                          <tr>
                                                    <td>Password:</td>
                                                    <td><input type="password" name="pwd"></td>
                                          </tr>
                                          <tr>
                                          <td></td>
                                          <td>
    <input type="submit" name="Add" value="submit">
    </td>
                                          </tr>
                                 </table>      
                       </form>
              </body>
    </html>
     

    Actions.php:

    <?PHP
    if(isset($_GET['emp_login']) && $_GET['emp_login']==login) //emp_login reference of pervious page//
    {
              if(isset($_POST['Add'])=="submit") //previous page submit button name
              {
                       $name="jack";        //$name is variable and stored username is jack
                       $pwd="jack123";      //$pwd is variable and stored password is jack123
                       $username=$_POST['u_name'];     // entered username in the login form
                       $pass=$_POST['pwd'];        // entered password in the login form
              if(($name==$username) && ($pwd==$pass)) // here validate stored and entered values match//
                       {
                                 header("location:dashboard.php"); // After successful forwarding home page//
                       }
                       else
                       {       
                                 header("location:login.php"); //Invalid username or Password
                       }
              }
    }
    ?>


    Dashboard.php:


    <?PHP echo "You Successfully login & entered Home Page"; ?>
                               Running Process in Any one Web Browser
     
    Login form in web browser :( login.php)



    After successful login :( dashboard.php)