Last active
October 21, 2019 12:16
-
-
Save andybeak/979822acc10a4dc973da726ca3981813 to your computer and use it in GitHub Desktop.
Log out a user using server-side sessions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// can't log out if the session isn't started | |
session_start(); | |
// emptying the session data is useful if your script continues running after logging out | |
$_SESSION = []; | |
// set the cookie to expire immediately | |
if (ini_get("session.use_cookies")) { | |
$params = session_get_cookie_params(); | |
setcookie(session_name(), '', time() - 42000, | |
$params["path"], $params["domain"], | |
$params["secure"], $params["httponly"] | |
); | |
} | |
// destroy the session on the server | |
session_destroy(); | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment