我不明白下面的代码,也不知道何时在session_start()之前使用session_id().
<?php
if($_GET){
//defining the session_id() before session_start() is the secret
session_id($_GET['session_id']);
session_start();
echo "Data: " . $_SESSION['theVar'];
//use your data before below commands
session_destroy();
session_commit();
}else{
//common session statement goes here
session_start();
$session_id=session_id();
$_SESSION['theVar'] = "theData";
echo "your.php?session_id=" . $session_id;
}
?>
我要你解释一下!不只是复制php.net的描述!
另一方面,session_id()在哪里使用?它的用途是什么?
先感谢您 !
解决方法:
可以说,在开始会话之前设置会话ID可以使您手动“恢复”会话.如果您没有设置ID的session_start()并且上一个会话已过期,它将生成一个新的ID并开始一个全新的会话.
从PHP文档中:
If id is specified, it will replace the current session id. session_id() needs to be called before session_start() for that purpose.
查看更多:http://php.net/manual/en/function.session-id.php