Skip to content

Instantly share code, notes, and snippets.

@miclaus
Last active April 20, 2017 14:34
Show Gist options
  • Save miclaus/9d9afe9f0128df731b907660ee2320a9 to your computer and use it in GitHub Desktop.
Save miclaus/9d9afe9f0128df731b907660ee2320a9 to your computer and use it in GitHub Desktop.
Kills PHP session.
<?php
// NOTE: see http://www.php.net/manual/en/function.session-destroy.php
function session_kill() {
// Unset all of the session variables.
session_unset();
// $_SESSION = [];
// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if ( ini_get('session.use_cookies')) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params['path'], $params['domain'],
$params['secure'], $params['httponly']
);
}
// Finally, destroy the session.
session_destroy();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment