note 48853 modified in function.session-destroy by tularis
| From: | tularis@php.net | Date: | Sun, 09 Jan 2005 15:06:59 +0000 |
| Subject: | note 48853 modified in function.session-destroy by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-82987@lists.php.net to get a copy of this message | ||
[Editor's Note]
doing $_SESSION = array();
is faster/quicker and works aswell.
[/Note]
If you want to keep your session_id() unchanged, but you want to reset all session variables, BEWARE
of unset($_SESSION). Doing so, and setting session variables (like $_SESSION['test'])
afterwards has the effect, that your changes will not be saved at the end of your script (not even
with session_write_close()).
So you better code like this:
foreach ($_SESSION as $VarName => $Value) {
unset ($_SESSION[$VarName]);
}
$_SESSION['test'] = 'MyTestValue';
--was--
If you want to keep your session_id() unchanged, but you want to reset all session variables, BEWARE
of unset($_SESSION). Doing so, and setting session variables (like $_SESSION['test'])
afterwards has the effect, that your changes will not be saved at the end of your script (not even
with session_write_close()).
So you better code like this:
foreach ($_SESSION as $VarName => $Value) {
unset ($_SESSION[$VarName]);
}
$_SESSION['test'] = 'MyTestValue';
http://php.net/manual/en/function.session-destroy.php