The session is used to access the various pages of an entire website. A session creates a temporary directory on the server. With the help of session variables and their value are stored .
The data will available to all pages on the site. If you are working on an application you need to start it and destroy it.
In simple words- First of all, you have to start the session and destroy the session.
If you want to get the value on next page(like username on another page) for that session will help you.
A PHP session is normally starts by making a call to the session_start() function .
The function session_start() first checks if session is already started and if session is not started then it starts one .
It is mandatory to start the session on every page. The session starts at the beginning of the page.
The session variables are stored in an associative array called $_SESSION.
A simple example of login page in session .
PHP Start a session .
$res=mysqli_query ($cser,"SELECT* from regis where email='$a' and password='$b'");
echo "you are login";
echo "failed" ;
In above example session started at the beginning .
Session destroyed .
Session destroyed means you want to logout (destroyed) the session . When a user login and at the end of his work he want to logout then the session destroyed will help you .
In above example first of session started and then session session destroyed .
If the session is destroyed the user will redirect to the main login page where the user can login again just put id and password.
With the help of other examples.
In the below example starts a session at the beginning of a page and register a variable call count . The count variable will increment each time when the user is visited page during the session .
Now we will use the isset () function to check if the session is already set or not.
if( isset( $_SESSION['count'] ) )
$_SESSION['counter'] += 1;
$_SESSION['count'] = 1;
$msg = "You have visited this page ". $_SESSION['count'];//Counts value
$msg .= "in this session.";
<title>PHP Session </title>
<?php echo ( $msg ); ?>
session_destroyed() function is used to destroyed a session . The function does not required any type of arguments and the single call destroyed the session variable.
You can use unset() function to unset a session variable . You can use unset() function to destroyed a single session variable .
The example of single session unset .
PHP Modify session .
To modify a session you have to overwrite it .
$_SESSION["favcolor"] = "yellow";
The example of destroyed the all session .