Session in php

January 1, 2013
Posted by admin 3:51 AM

 Session is a way to preserve some useful information on the server .It is a variable that stores information of a user on the server side. Sessions are temporary when a user logged out it destroyed.

For further use of session records we have to save it in database.However it is like a variable to store information but it need to be define on one page and we can use this variable on other pages also without redefining that variable on other page.
When we works on a computer the computer have the information about the user but on the server side the information about a user can be keep with help of session. Everytime when a user logged in each time a unique session id is creted called (UID).to create a session Id we have to start the session before the HTML tag


<?php  session_start();  ?>





The above code can register a session with the server and create a unique ID for this user .Now we can create session variables to use on other pages. From the above code the server start to save session information to create a session variable we use $_SESSION.


<?php  session_start(); ?>




If  we want to delete some session data we can use unset () function  or session_destroy() function.While unset()  function is used to delete a specific variable while session_destroy() function  can completely destroy the session


<?php  session_start();