function killsession()
{
// global $_SESSION;
$_SESSION = array();
if (session_id() != "" || isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time() - 42000, '/');
}
session_unset();
session_destroy();
header("Location: "index");
}
Any ideas why $_SESSION[‘userid’] still stands after I run this function? I literally stay logged in.
Session name and start() is set at the top of every page.
As found on the PHP session_destroy() manual:
Example directly from PHP Manual:
Applying this example to your function:
Consider this two session variables:
The output for
print_r($_SESSION);, will be:After calling the
killsession()function, the output will be:See this working example. Errors are suppose to appear in this environment due to previous outputs and headers being performed by the
print_randsessioninteractions.