我一直想知道,如果 PHP 会话在执行脚本期间超时,那么 $_SESSION 数组的内容是否仍然可用,直到脚本执行结束?例如:
session_start();
if(! isset($_SESSION['name'])) {
echo 'Name is not set';
exit;
}
// imagine there is a bunch of code here and that the session times out while
// this code is being executed
echo 'Name is ', $_SESSION['name']; // will this line throw an error?
将会话变量复制到本地范围是否可行,以便稍后在脚本中读取它们而不必继续检查会话超时?就像是:
session_start();
if(isset($_SESSION['name'])) {
$name = $_SESSION['name'];
} else {
echo 'Name is not set';
exit;
}
// bunch of code here
echo 'Name is ', $name;