Consider the following code:
<?php
if (!session_id())
session_start();
echo session_id();
session_destroy();
?>
How come everytime I refresh this page it shows the same session id, even though the session gets destroyed and recreated each time? Isn’t the session id cleared upon session destruction?
EDIT:
I’ve used this updated code, based on the favorite answer- however, the session id STILL perists! Any ideas?
if (!session_id())
session_start();
echo session_id();
// Unset all of the session variables.
$_SESSION = array();
// 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();
http://php.net/manual/en/function.session-destroy.php
The manual comes with a code-example:
Example #1 Destroying a session with $_SESSION
** Update **
PHP Version 5.3.6-13
Linux lime 3.0.0-1-686-pae #1 SMP Wed Aug 17 04:28:34 UTC 2011 i686
Apache/2.2.19 (Debian)
Session Settings (phpinfo)
Update
So. Following settings results in the same problem. if, and only if i’m sening the session id as a request parameter locahost?PHPSESSID=whatever
IMPORTANT:
this settings are valuable to Session Hijacking [Session fixation]