note 19198 modified in function.session-destroy by erica
| From: | erica@php.net | Date: | Sat, 05 Oct 2002 21:55:04 +0000 |
| Subject: | note 19198 modified in function.session-destroy by erica | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-37708@lists.php.net to get a copy of this message | ||
NOTE: This code will not work if you are using $_SESSION or have register_globals turned off.
--erica@php.net
session_destroy and friends are a bit recalcitrant at times; While (unsuccesfully ) attempting to
build a multi-session logout, I came across this code (I forget the original author - my apologies)
that really saved my sanity.
function session_clear() {
// if session exists, unregister all variables that exist and destroy session
$exists = "no";
$session_array = explode(";",session_encode());
for ($x = 0; $x < count($session_array); $x++) {
$name = substr($session_array[$x], 0, strpos($session_array[$x], "|"));
if (session_is_registered($name)) {
session_unregister('$name');
$exists = "yes";
}
}
if ($exists != "no") {
session_destroy();
}
}
session_clear();
--was--
session_destroy and friends are a bit recalcitrant at times; While (unsuccesfully ) attempting to
build a multi-session logout, I came across this code (I forget the original author - my apologies)
that really saved my sanity.
function session_clear() {
// if session exists, unregister all variables that exist and destroy session
$exists = "no";
$session_array = explode(";",session_encode());
for ($x = 0; $x < count($session_array); $x++) {
$name = substr($session_array[$x], 0, strpos($session_array[$x], "|"));
if (session_is_registered($name)) {
session_unregister('$name');
$exists = "yes";
}
}
if ($exists != "no") {
session_destroy();
}
}
session_clear();
http://www.php.net/manual/en/function.session-destroy.php