PHP Login Example with session

In this example you have create 2 PHP files .

                                                   File Name : index.php

<?php
        session_start(); //start session
        if(isset($_POST['click']))
       {
              $_SESSION['user']=$_POST['username']; //set value of username in session varible
              header("Location:file2.php");
              exit;
       }
?>
<html>
      <body>
           <form method="post">
                 <input type="text" placeholder="Enter Username" name="username"/><br/>
                 <input type="password" placeholder="Enter Password" name="password" /><br/>
                 <input type="submit" name="click" value="Click Here">
                 <input type="reset" name="cancel" value="Cancel">
          </form>
     </body>
</html>




                                                     File Name : file2.php 

 <?php
        session_start();
        echo "WELCOME ".$_SESSION['user'];
?>

Comments

Popular posts from this blog

Shutdown Computer With Funny Reason

Hidden Attribute in javascript

Draw animated loading spinner canvas in Javascript