-1

Is there any risk of a session expiring before the other session even if they're declared at the same time?

I want to declare 40+ variables as sessions, but only if they didn't already exist, like so:

if (!array_key_exists('user', $_SESSION))
{
$_SESSION['user']['username'] = "";
$_SESSION['user']['age'] = "";
$_SESSION['user']['location'] = "";
//...and 40+ more
}

But if one of those sessions expired before the others, it would ruin the whole code. Is that a possibility?

Thank you!

4

2 回答 2

2

$_SESSION 是一个关联数组。因此,您存储在其中的东西不是单独的“会话”,而是数组中的值。由于会话到期时 $_SESSION 被丢弃,因此它的所有值同时消失。

所以不:$_SESSION 数组中的一个这样的值不会先于另一个过期,它们同时过期。有关使用会话和 $_SESSION 的更多信息:http ://www.php.net/manual/en/session.examples.basic.php

于 2013-06-15T18:11:35.877 回答
1

在 php.ini 中为 session.gc_maxlifetime 设置的值是以秒为单位的 ID 生命周期。

我认为默认是 24 分钟。

还要检查这个:http : //www.php.net/manual/en/session.configuration.php 变量有限制吗?不,那里没有!

于 2013-06-15T18:07:42.960 回答