Php Session

PHP Session@ Shwetank education.com

Script   PHP Session
Using sessions in PHP allows you to store temporary information of a user on the server which can be passed from one page to another whilst the user is surfing your site. It is automatically destroyed once the user has left your site.

Syntax

<?php

session_start();
?>

Session Example With User Login
PHP code   Login .php

<?php
if(isset($_REQUEST[“btn”]))
{
$uid=$_POST[“t1”];
$pwd=$_POST[“t2”];
if($uid==’jit@gmail.com’&&$pwd==’123′)
{
session_start();
$_SESSION[“visitor”]=$uid;
header(“location:welcome.php”);
}
else
{

}
}
?>

HTML Code

<form id=”form1″ name=”form1″ method=”post” action=””>
<table width=”300″ border=”0″>
<tr>
<td>User id </td>
<td>

After Session Login User Go Welcome Page
welcome.php

<?php
$id=””;
session_start();

if(isset($_SESSION[“visitor”]))
{
$id=$_SESSION[“visitor”];
}
else
{
header(“location:index.php”);// header function use to transfer the next page
}

?>
welecome: <?=$id?>

Session Destroy { Logout}
<?
if(isset($_GET[“btn”]))
{
session_destroy();// inbuilt function in php
header(“location:index.php”);
}
?>
<form action=”” method=”get”>
<input name=”btn” type=”Signout” />
</form>