-
Step 1
To start a new session in PHP we use the code:
session_start();
This creates a brand new session and a unique session identification number which can be obtained by using the built in function code:
session_id(); -
Step 2
Once you have your session created you start adding values to your session by assigning the values what are called session variables. For example you can use:
$_SESSION['firstname']='mike';
Firstname is the session variable and 'mike' is its value. If you ever want to retrieve the value of firstname you would write this code:
echo $_SESSION['firstname']; -
Step 3
Now that you know how to start a session and assign variables within a session, you need to know how to clear a session. This is simple. You use the built in function session_destroy();
This will clear all of the variables and their values within a session, but it does not however clear the session_id value. That will remain.










