PHP session variable is employed to store the data about,or amendment
settings for a user php session tutorial. Session variables hold data concerning one
single user, and are available to all pages in one application.
- In Session variable, session data is temporary and can be deleted when the user has left the web site,If you would like a permanent storage,then you will wish to store the data during database.
Starting a PHP session:
php session can be started by calling a function called Session_Start( ). The function initially checks if a session is already started and if none is started then it starts one. It is counseled to place the decision to call to session_start() at the start of the page.- Session_Start function should appear before the <html> tags.
| <?phpsession_start();?><html> <body> <p>This is our paragraph</p> </body> </html> |
Storing a session variable:
We can also store the session variable,see the example below:| <?php session_start(); // store the session $_SESSION[‘store’]=9; ?><html> <body><?php //retrieve session data echo “Pagestore=”. $_SESSION[‘store’]; ?></body> </html> |
Destroy a session variable:
By using unset() function or the session_destroy() function you can delete session data.| <?php session_destroy(); ?><html><body><p> This is a paragraph </p> </body> </html> |
No comments:
Post a Comment