简体   繁体   English

会话变量已设置,但PHP报告未设置?

[英]Session variable is set, but PHP reporting it is not set?

print_r($_SESSION);

gives me this: 给我这个:

[post] =>
[verify] => 3bae5359ea60d7f00d553ae5d091ae4b
[token] =>

token is set, but null, right? 令牌已设置,但为空,对吧? When I implement this: 当我实现这个:

if (!isset($_SESSION['token'])) {
    die("Token not set");
}

The script dies. 脚本死了。 Why is this happening? 为什么会这样?

From the documentation - 文档 -

bool isset ( mixed $var [, mixed $... ] ) bool isset(混合$ var [,混合$ ...])

isset determines if a variable is set and is not NULL isset确定变量是否已设置且不为NULL

Also - 还 -

Return Values: Returns TRUE if var exists and has value other than NULL, FALSE otherwise. 返回值:如果var存在且值不是NULL,则返回TRUE,否则返回FALSE。

So, if the supplied argument contains NULL or if it simply doesn't exist, then isset will return FALSE . 因此,如果提供的参数包含NULL或者它根本不存在,则isset将返回FALSE This is exactly what is happening with your script and as a result, it dies. 这正是您的脚本正在发生的事情,因此,它会死亡。

$ _SESSION ['token']没有任何价值,这就是为什么它会在条件和死亡时陷入其中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM