Session Example


This program is used for session example in php. Session is used to store information, or change settings for a user session it holds the information about one single user, and those are available for all pages in one  application.


SessionExample.php here you will post your data in form and all data will be get stored in session variables.

<?php
session_start();
  if($_POST[request])
{
  $_SESSION['name'] = $_POST['nm'];
  $_SESSION['email'] = $mail=$_POST['mail'];
  $_SESSION['usrnm'] = $_POST['user'];
  $_SESSION['pswd'] = $_POST['pwd'];
  echo "<script type='text/javascript'>window.location.href='sesionpage.php'</script>";
}

?>
<html>
<head>
<title>Session Example</title>
<style>
  input[type="text"]
  {
    margin-top:5px;margin-left:8px;border: solid #00BFFF;border-radius:25px;
  }
  input[type="password"]
  {
    margin-top:5px;margin-left:8px;border: solid #00BFFF;border-radius:25px;
  }
  input[type="submit"]
  {
    height:50px;margin-left:65px;margin-bottom:10px;border: thick #56aa64;border-radius:25px;border: solid #00BFFF;
  }
</style>
</head>
<body width="600" >
<div style="width:200px;margin-left:100px; margin-top:50px;background-color:#56aa64;border-radius:25px;border: solid #00BFFF;">
  <form method="post">
    <br>&nbsp;Name<br>
    <input  type="text" name="nm"><br><br>
    &nbsp;Email ID<br>
    <input type="text" name="mail"><br><br>
    &nbsp;Username<br>
    <input type="text" name="user"><br><br>
    &nbsp;Password<br>
    <input type="password" name="pwd"><br>
    <br>
    <input type="submit" name="request" value="Submit">
  </form>
</div>
</body>
</html>

Output : 




sesionpage.php this page will display the data stored in session variables.

<?php
session_start();
$name = $_SESSION['name'];
$email = $_SESSION['email'];
$user = $_SESSION['usrnm'];
$pwd = $_SESSION['pswd'];
echo '<html>
  <head>
    <title>Session Variables</title>
  </head>
  <body width="600" >
    <div style="width:250px;margin-left:100px; margin-top:50px;background-color:#56aa64;border-radius:25px;border: solid #00BFFF;">
    <br>&nbsp;&nbsp;Name : '.$name.'<br><br>&nbsp;&nbsp;Email ID : '.$email.'<br>           <br>&nbsp;&nbsp;Username : '.$user.'<br><br>&nbsp;&nbsp;Password : '.$pwd.'<br>&nbsp;
    </div>
  </body>
</html>';
?>

Output :


0 Comments:

Post a Comment