Tuesday, 29 September 2015

Login with session in php

********login*************
  <form action="checklogin.php" method="post">
    <table>
 
    <tr>
       <td>Loginid:</td>
      <tD><input type="text" name="t1"></td>
      </tr>
     <tr>
       <td>Password:</td>
      <tD><input type="password" name="t2"></td>
      </tr>
          <tr>
           <td>&nbsp;</td>
           <td><input type="submit" value="submit">
      </tr>
  </table>
  </form>

*************chack.php*******

  <?php
     session_start();
     $l=$_REQUEST["t1"];
     $p=$_REQUEST["t2"];
     $conn=new PDO("mysql:dbname=ssit","root","");
     $result=$conn->query("select *From registration where loginid='".$l."' and password='".$p."'");
   if($row=$result->fetch())
    {
      echo "welcome user ".$row["name"];
      $_SESSION["u"]=$row["rid"];
     ?>
      <br>
      <a href="changeprofile.php">change profile</a>
  <?php
    }
    else
    {
        header("Location:login.php");
    }
  ?>
*****************sessio**********
<?php
session_start();
?>
<html>
<head>
<title>USe of Data</title>
</head>
<body>
<form action="session4.php" method="post">
<?php
if(isset($_SESSION['t1']))
{
echo "Welcome".$_SESSION['t1'];


?>
<input type="submit" name="submit" value="Logout" />
<?php
}
else
{
header("Location:session.php");
}
?>
</form>
</body>
</html>
***********************4**********
<?php
session_start();
session_destroy();
header("Location:session.php");
?>

No comments:

Post a Comment