In your readings, you may have come across mention of PHP Sessions. Sessions are another mechanism, in addition to the $_GET, $_POST, and $_COOKIE variables that allow you to “maintain state”, meaning to pass data from one page to another.
Session variables are just like cookies, but easier
PHP provides a set of functions that allow you to read and write session variables. The basic idea is that session variables allow you to store data for as long as the user’s session is still alive. Generally, a session is alive as long as the user’s browser is open, just like cookies. These session variables can be accessed from any page on the site, just like cookies.
These are variables that are stored on the server, and last for a limited amount of time. They are functionally very similar to cookies, and in fact PHP does use cookies to perform most of the tasks involved with Sessions. But PHP hides the internal details of how Sessions work, which makes your job a little bit easier.
How to use sessions in PHP
Any script that uses session variables, either to read or write them, needs to call the session_start() bult-in PHP function at the top of the script. This is just a command to tell PHP that you want to use sessions on this page.
Once you have done that, you can create a session variable like this:
//create a session variable called "test_variable" $_SESSION['test_variable'] = "this is the value of the test variable";
Once you have created a session variable, any other page on your site can access that variable like so:
//echo the value of the session variable called "test_variable" echo $_SESSION['test_variable'];
Example Files
Here is an example of a script that writes a session variable, just like the example code above.
And this page reads that same variable and outputs it to the page.
Further reading
Here are some pages that cover sessions, and explain how to write PHP code to deal with them:
http://php.about.com/od/advancedphp/ss/php_sessions.htm
http://www.tizag.com/phpT/phpsessions.php
http://www.htmlgoodies.com/beyond/php/article.php/3472581
http://us3.php.net/session