note 101789 deleted from function.session-regenerate-id by danbrown
| From: | danbrown@php.net | Date: | Tue, 11 Jan 2011 15:41:43 +0000 |
| Subject: | note 101789 deleted from function.session-regenerate-id by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-175643@lists.php.net to get a copy of this message | ||
Note Submitter: sietse dot au at gmail dot com
----
@ Ben Johnson
Your code works, but why are you doing so much more effort.
<?php
// initialize session data based on new or existing session id
session_start();
// get a new session id and delete the old associated session file (which is linked with the old
session id)
session_regenerate_id(true);
// free all variables in $_SESSION, the $_SESSION in the current script still exists, but the
associated session file is gone. The data in $_SESSION can not be retrieved anymore from the
filesystem.
session_unset();
?>
What we have here is:
A empty $_SESSION superglobal
A new id and a new associated session file
The old session associated file is deleted so if you change your session id to the old one and
initialize the data with session_start(), it just creates a new session associated file