Possible Duplicate:
Close session and start a new one
I use wampserver2.1 php5.3.3, I found session_regenerate_id(true) not work in my script,document says when I set the parameter 'delete_old_sessions' true, there should be a new sid and all the session variables should be deleted, but the fact is after the function, $_session[abc] is still there. did I misunderstand the function,what is my problem? I appreciate if anyone can help me,
<?php
session_start();
$_SESSION['abc']=12323;
session_regenerate_id(true);
echo $_SESSION['abc'];
?>
I thought it should display none, but it outputs:12323
session_regenerate_id()
updates the currentsession id
with a newly generated one. It does not change session variables.You should
unset
session to do that:How to start a new session:
If you want to destroy the session-variables you can perform this:
session_destroy();
and if you want to get new ID you cansession_regenerate_id();
session_regenerate_id
sends a new cookie but doesn't overwrite the value stored in$_COOKIE
. After callingsession_destroy
, the open session ID is discarded, so simply restarting the session withsession_start
will re-open the original, though now empty, session for the current request (subsequent requests will use the new session ID). Instead ofsession_destroy
+session_start
, use the$delete_old_session
parameter tosession_regenerate_id
to delete the previous session data.To start a new session and leave the old untouched, simply leave out the argument to
session_regenerate_id
.Source: http://de.php.net/manual/en/function.session-regenerate-id.php#107323