Forum Moderators: coopster
function logoff() {// kill session variables
unset($_SESSION["user"]);
unset($_SESSION["pass"]);
session_destroy();
setcookie("user", NULL, time()-3600);
setcookie("pass", NULL, time()-3600);
// redirect them to anywhere you like.
header("Location: index.php");
}
I call it in the script like this with a link login.php?logoff
if (isset($_GET["logoff"]))
logoff();
When I am logged in it does log me off but does not redirect me to the index page as expected. if I use the same link and am not logged in it does redirect me to the index page. Any ideas as to what is wrong with it?
Thanks
Brandon
[php.net...]
function logoff() {// kill session variables
unset($_SESSION["user"]);
unset($_SESSION["pass"]);
unset($_SESSION["logged_in"]);
unset($_SESSION["admin"]);
session_destroy();
setcookie("user", NULL, time()-3600);
setcookie("pass", NULL, time()-3600);
// redirect them to anywhere you like.
header("Location: index.php");
}
Is there a way to just unset all session variables? Will I have to update this every time I set a session parameter for the logout to redirect?
Thanks for your help
ession_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie.In order to kill the session altogether, like to log the user out, the session id must also be unset. If a cookie is used to propagate the session id (default behavior), then the session cookie must be deleted. setcookie() may be used for that.
Is there a way to just unset all session variables?
$_SESSION = array();