Tuesday, August 25, 2009

Destroying a session completely in php

Interesting snippet of code. To completely destroy a session and all associated data including any cookies

session_start();

//Clear out all session data
$_SESSION = array();

//if a cookie is set set the cookie expiry date to yesterday
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-86400, '/');
}

//destroy the session
session_destroy();

No comments:

Post a Comment