1

I found session_regenerate_id will not work it together with session_destroy(), please see this one works

<?php
   session_start();
   $old='old is: '.session_id();
   session_regenerate_id(true);
   echo $old;
   echo '<br>';
   echo 'new is: '.session_id();     
?>

this one failed, return 2 same session id numbers

<?php
   session_start();
   $old='old is: '.session_id();
   session_regenerate_id(true);
   session_destroy();
   session_unset();
   session_start();
   echo $old;
   echo '<br>';
   echo 'new is: '.session_id();     
?>

I use php 5.3.3, the second one is a recommended method to produce a new session, but why it does not work on my side.

thanks everyone,after tests, I found session_destroy must be invoked before session_regenerate_id(), or session_regenerate_id never works.

<?php
session_start();
$_SESSION['abc']=12323;
$old='old is: '.session_id();
session_unset();
session_destroy();
session_start();
session_regenerate_id(true);
echo $old;
echo '<br>';
echo 'new is: '.session_id();   

?>

4

3 回答 3

0

地方

session_unset();

以上 session_destroy(); 或删除 session_unset(); 完全地。当您破坏会话时。

试试这个代码:

<?php
   session_start();
   $oldSessionId ='Old session ID is: ' . session_id() . '<br />';
   echo $oldSessionId;
   session_destroy();
   session_start();
   session_regenerate_id(true);
   echo 'New session ID is: ' . session_id();     
?>

如果您愿意,还可以在 session_destroy() 之后添加以下代码

setcookie(session_name(),'',0,'/');

希望这可以帮助

于 2012-10-09T11:27:54.377 回答
0
session_start();
$old='old is: '.session_id();
session_destroy();
session_start();
session_regenerate_id(true);
echo $old;
echo '<br>';
echo 'new is: '.session_id();    
于 2012-10-09T11:40:13.893 回答
-1

您应该首先销毁会话。尝试这个:

session_destroy();
session_unset();
setcookie(session_name(), null, 0, "/");
于 2012-10-09T11:33:04.957 回答