Loading...
PHP

Session

Session is a state management object using to access values of one page from another page. Session can store information in web server by using $_SESSION we can create the session and we can access the sessions.

Session id: 
Session id is in alpha numeric string generated by web server. When user is sending a request to the server. It is a unique id collection of alphabet and numbers. When the server is receiving a request from client system. First it checks whether the request contains any session id or not. If request doesn’t contains any session id then server creates a new session id to that user. At the same time server temporary memory location creates, if file to maintain session data of that user file name is same as session id with prefix sess_. At the same time server sends response to the client system along with session id and stores session id as in memory cookie in client system. The name of COOKIE is PHP SESSID and value is session id from next request onwards same session id will transfer between browser and server. When user closed the browser in memory cookie will destroy again. If we send the request to the server the request is transfer without any session id then again server creates new session id to that user

SESSION_ID: By using this function we can get the session id, what is generated by web server.

SESSION_UNSET: By using this function we can delete the data of sessions.

SESSION_DESTROY:  To destroy the data of entire sessions.

<?php
if(isset($_POST[‘sub’]))
{
$pro= $_POST[‘drp1];
$qty= $_POST[‘t1’];
echo session_id();
$_SESSION[$pro]=$QTY;
}
?>
<form method=”post” action= ” “>
pname: <select name= “drp1”><option> samsung </option> <option> Nokia </option> Bbery </option> </select> <br>
Quantity: <input type= “text” name=”t1″> <br
                  <input type=”submit” name=”sub” value=”add”>
</form>
<a href= “bill.php”> Bill  </php>

-> <?php
     session_start();
     echo session_id();
     echo “<br>”;
     for each($_SESSION as $k=>$v)
     {
     echo $k;
     echo “=”;
     echo $v;}
     echo “<br>”;
     ?>

Leave a Reply

Your email address will not be published. Required fields are marked *