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.

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.

$_SESSION['name']="zaibi shah";

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.

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. said,

    Thanks for share !

    Please visit my blog

    on July 11, 2011 at 6:43 AM  

Post a Comment