Working with Sessions How do you store the information into the session created recently. First you have to register the variable with the session created. After that you can use that variable to store user information. The code provided below will show how. Note that the code should be used after the session is created. If the 'session_start()' is not called before, then an implicit call to this function will be made without any argument.
session_register("sess_var"); $sess_var = "variable1"; print "Value of session variable: "; print $sess_var; ?>
If the variable is successfully registered then the 'session_register()' function will return a boolean value, ie true or false. So, you can easily check that the variable is registered with the session or not.
Destroying a session Once the user is done with his/her payment for online shopping, all variables and sessions associated with the user should be cleared for security purpose. Before the session is destroyed all variables are needed to unset. Because only destroying the session does not reset all the variables and also the session cookie. So the function 'session_unset()' resets all the variables of the current session. The code for destroying session is as follows:
session_start(); $_SESSION = array(); if (isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time()-42000, '/'); } session_destroy(); ?>
The function 'array()' above is meant unset all the variables of the current session, ie, 'unset($sess_var).' And then finally destroy the current session.
Get most out of your technology infrastructure investments with Dell
About CIOL | Media Kit | Site Map | Contact Us | Help | Write to us | Jobs@CyberMedia | Privacy Policy
Copyright © CyberMedia India Online Ltd. All rights reserved. Usage of content from web site is subject to Terms and Conditions.