Wednesday, May 15, 2013

How Sessions Work?



Session are handled in PHP by using the function session_start(). This function should be invoked before any HTML tags in the script.
Ex. 
<?php
session_start( );
?>
<html>
<head> ....... etc
A random session id is generated by the function session_start(). This session id is persisted in a cookie on the client / user computer. To refer the cookie, the reference variable $PHPSESSID is used. This is the default session id. The session id can be changed in the PHP configuration files on the server.
Even the user returns this page after visiting some pages, PHP keeps track about this session and its progress. Subsequent to this process, the session can be used as follows –
print $PHPSESSID; 
session_register("username");
 
print $username;
The user name is registered and by using session variable name username and used it for display.
....... etc A random session id is generated by the function session_start(). This session id is persisted in a cookie on the client / user computer. To refer the cookie, the reference variable $PHPSESSID is used. This is the default session id. The session id can be changed in the PHP configuration files on the server. Even the user returns this page after visiting some pages, PHP keeps track about this session and its progress. Subsequent to this process, the session can be used as follows – print $PHPSESSID; session_register("username"); print $username; The user name is registered and by using session variable name username and used it for display.

No comments:

Post a Comment