note 53480 added to function.session-regenerate-id
| From: | Nicolas dot Chachereau at Infomaniak dot ch | Date: | Thu, 02 Jun 2005 18:40:42 +0000 |
| Subject: | note 53480 added to function.session-regenerate-id | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-89829@lists.php.net to get a copy of this message | ||
Session_destroy() does not only destroy the data associated with the current session_id (i.e. the
file if you use the default session save handler), but also the session itself: if you call
session_destroy() and then session_regenerate_id(), it will return false, and session_id()
won't return anything. In order to manipulate a session after destroying it, you need to
restart it.
So in fact, the code mentionned by chris won't work. If you want to destroy the file associated
with the old session_id, try the following:
<?php
session_start();
$old_sessid = session_id();
session_regenerate_id();
$new_sessid = session_id();
session_id($old_sessid);
session_destroy();
//If you don't copy the $_SESSION array, you won't be able to use the data associated with
the old session id.
$old_session = $_SESSION;
session_id($new_sessid);
session_start();
$_SESSION = $old_session;
//...
?>
Note: this technique will send 3 Set-Cookie headers (one on each session_start() and one on
session_regenerate_id()). I don't think this is a problem, but if it appears to be one, you
could either leave it alone and wait for the garbage collector to catch the file associated with the
old session, or try to delete the file with unlink().
----
Manual Page -- http://www.php.net/manual/en/function.session-regenerate-id.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+53480
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53480&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53480&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53480&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53480&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53480&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+53480&report=yes
Search -- http://master.php.net/manage/user-notes.php