Share on Google+Share on Google+

Destroying the session

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.


bool session_decode ( string $data )




$_SESSION = array();
if (isset($_COOKIE[session_name()])) {
echo setcookie(session_name(), '', time()-42000, '/');

The Output:

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


Posted on: July 31, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.