小编Tim*_*Tim的帖子

如果PHP会话在请求中间超时,$ _SESSION数组会发生什么?

我一直想知道,如果一个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?
Run Code Online (Sandbox Code Playgroud)

将会话变量复制到本地作用域是否切实可行,以便稍后在脚本中读取它们而不必继续检查会话超时?就像是:

session_start();

if(isset($_SESSION['name'])) {
    $name = $_SESSION['name'];
} else {
    echo 'Name is not set';
    exit;
}

// bunch of code here

echo 'Name is ', $name;
Run Code Online (Sandbox Code Playgroud)

php session session-timeout

3
推荐指数
1
解决办法
1614
查看次数

标签 统计

php ×1

session ×1

session-timeout ×1