session_destroy() will not delete the cookie on the client side by itself, so the next time they visit the user, they will still have the same session identifier (but their session information on the server side will be destroyed).
From the documents (my selection):
session_destroy () destroys all data associated with the current session. It does not cancel any global variables associated with the session or disable the session cookie .... In order to kill the session altogether, as well as for user login, the session identifier must also not be set . If a cookie is used to propagate a session identifier (default behavior), then the session cookie must be deleted.
You can use session_regenerate_id(true) to create a new session id and delete the old one. Note that this will contain all the information in $_SESSION as part of the new session identifier, so you still need to use session_destroy if you want to clear the session information and start a new one.
eg.
<?php session_start(); $_SESSION['blah'] = true; var_dump(session_id()); // q4ufhl29bg63jbhr8nsjp665b1 var_dump($_SESSION); // blah = true session_unset(); session_destroy(); setcookie("PHPSESSID", "", 1); // See note below session_start(); session_regenerate_id(true); var_dump(session_id()); // gigtleqddo84l8cm15qe4il3q3 var_dump($_SESSION); // (empty) ?>
and the headers will show the change in the session identifier on the client side:
Request header
Cookie: PHPSESSID = q4ufhl29bg63jbhr8nsjp665b1
Answer Header
Set-Cookie: PHPSESSID = deleted; expires = Mon, Dec 27, 2010 4:47:57 p.m. GMT
PHPSESSID = gigtleqddo84l8cm15qe4il3q3; Path = /
(You can do without calling setcookie() here since you are still creating a new session, so the cookie will be overwritten with the new identifier, but it is good practice to explicitly destroy the old cookie).
source share