Reputation: 109
I have read similar ways to log out, but none of them seem to work for me. I Have used all this combinations on my logout.php page:
<?php
session_start();
session_destroy();
$_SESSION = array();
$_SESSION['sec_session_id'] = "";
unset($_SESSION['session_name']);
echo '<script> window.location.assign("../index.php") </script>"'; //this line works fine
?>
But down the line, the only way to really log out is by closing the browser. Any ideas on what am I doing wrong?
Now, there´s another hope, making the cookie expire with setcookie("user", '', 1);
But I have no idea how to replace the word "user" :-/
Upvotes: 1
Views: 65
Reputation: 76
Please try this way...
//logout.php
//start session
session_start();
// clear session array
$_SESSION = array();
// if session set in cookie, force cookie to expire
if (isset($_COOKIE[session_name()]))
{
$cookie_expires = time() - date('Z') - 3600;
setcookie(session_name(), '', $cookie_expires, '/');
}
// destroy session
session_destroy();
// redirection to your location
header("Location: /");
exit;
Upvotes: 1