Destroying the session


 

Destroying the session

In this example you will learn about destroying the session in PHP.

In this example you will learn about destroying the session in PHP.

Destroying Session

Session_destroy() function is used for destroying all of the data associated with the current session. Neither it does not intervene any of the global variables nor the session cookie. For completely removing the session, it is usually used with session_unset() function. It returns TRUE on success or FALSE on failure.

Syntax 

bool session_decode ( string $data )

Parameters

data

Example:

<?php
session_start();
$_SESSION = array();
if (isset($_COOKIE[session_name()])) {
echo setcookie(session_name(), '', time()-42000, '/');
}
session_destroy();
?>
 

The Output:

As the time cross over 42000 seconds, the session would getexpired and all the related data will be deleted automatically.

Ads