memberlogin
contactus
randomfacts

Setting session variables with php

Session variables are a useful way to carry information that is unique to each visitor on your website, similar to cookies.  The value and the actual session variable itself will be destroyed after designated amount of time or when the visitor closes their browser windows.  Session variables are handy in that you don’t have to worry about passing a variable from page to page, instead you just create a session variable and call that value on any page within the website.


Session variables are set by placing the following code at the top of the page:
     session_start();


Then you will use the session_register to register the session variable name (the below code registers a session variable named myfirstsessionvariable).
    session_register(“myfirstsessionvariable”)


To set a value to the session variable use the following (the below code will set the value of the session variable myfirstsessionvariable equal to 123):
    $HTTP_SESSION_VARS ["myfirstsessionvariable"] = "123"; OR you can use this $_SESSION['myfirstsessionvariable'] = "123" 


To display the value of the session variable myfirstsessionvariable you can do the following:
    echo $_SESSION['myfirstsessionvariable'];


If you want to kill a specific session variable you can use the following command:
    session_unregister(“myfirstsessionvariable”)


When you are finished with all the session variables and want to end the session for the user (for example if they log out of a secured section of the website)  you simple use the following:
    session_destroy(“”)