Pages

PHP Sessions

Session is a way of keeping the user information on the server to recognize a particular user.The session information is a temporary arrangement of keeping the user data on the webserver which only lasts until the browser is not closed.
Sessions are implemented in a way that whenever a session is started a unique id (UID) is assigned to the user,this ID is than stored in a cookie or embedded in the URL.After that the $_SESSION array is used to hold different information based on that UID which was assigned to the user.

<?php
session_start();//start the session
?>


The session_start(); function starts a session by setting up a unique ID.This function must appears before the html tag.


<?php
session_Start();
$_SESSION['name']="zaibi shah";
$_SESSION['customer_id']=1;
?>


In the code above we have saved user information in two variables exist in the $_SESSION array.These two variables are saved on the server against the UID which was created by the session_start() function.


<?php
session_start();
echo "Your name is ".$_SESSION['name'];
echo "your ID is ".$_SESSION['customer_id'];
?>


The session information can later be retrieved with the help of the code shown above, this information will remain available for us until we don't close the browser.

 

1 comments:

  1. codeoop.com said,

    Thanks for share !

    Please visit my blog

    http://codeoop.com/2011/06/02/position-of-the-array-with-php/

    on July 11, 2011 at 6:43 AM  


Post a Comment