Session and storing, retrieving values
A session is used in php to temporarily store values as variables in the server.
A session value once stored will be available until
- the browser is closed
- session timeout is reached
- you remove the value from the session.
Unlike a cookie, the value is not stored on the users computer.
Starting a session:
You have to start a session to insert values in to the session
Storing a value:
// this function should be the first line on you page where you are to store the value.
Now we are to start a session and set a value in to a variable from a php page (say x.php).
Retriving a Value:
// setting values in to the session as variables
Consider we need that value in a different page (say y.php).
The code will be as follows
// session_start should always be the first line of code in you php page
//retrieving or getting the stored session value
echo "Stored value is ".$_SESSION['test'];