$_SESSION is a special array used to store information across the page requests a user makes during his visit to your website or web application.
Starting a Session and Storing a value in Session
Before you can to store information in a session, you have to start PHP’s session handling. To start the session session_start() is used -
<?php
// start them engines!
session_start();
// store session data
$_SESSION["username"] = "QueryHome";
session_start() starts the session between the user and the server, and allows values stored in $_SESSION to be accessible in other scripts later on.
Retrieving a Session Variable
You call session_start() again which continues the session in another file and you can then retrieve values from $_SESSION.
<?php
// continue the session
session_start();
// retrieve session data
echo "Username = " . $_SESSION["username"];
Ending a Session Variable
To delete a single session value, you use the unset() function:
<?php
session_start();
// delete the username value
unset($_SESSION["username"]);
Ending all the session variable
To unset all of the session’s values, you can use the session_unset() function:
<?php
session_start();
// delete all session values
session_unset();