简体   繁体   English

PHP会话变量不会取消设置

[英]PHP Session Variable Will Not Unset

I have a couple of lines of code in a Drupal module as so: 我在Drupal模块中有几行代码,如下所示:

if ($arg == 'true' && isset($_SESSION['xyz']['noredirect'])) {
    unset($_SESSION['xyz']['noredirect']);
}

When the 2nd line is executed, I get error: 当第二行执行时,我收到错误:

Error messageNotice: Undefined variable: _SESSION in blah() (line 122 of /home/xxxxxxx/public_html/sites/all/modules/blah/blah.module).

I simply cannot understand why if the session is set, I cannot unset it. 我简直无法理解为什么如果设置会话,我不能解开它。

Any ideas? 有任何想法吗?

Thanks 谢谢

It would appear that you are yet to run session_start() . 您似乎还没有运行session_start() This will create the $_SESSION superglobal. 这将创建$_SESSION超全局。

The module now works exactly as I want it to. 该模块现在完全按照我的要求工作。 I solved it by using session_destroy(); 我通过使用session_destroy()解决了它; rather than unset. 而不是未设置。 It's probably not the most elegant way of fixing it but it works and I couldn't find any other way to do so. 它可能不是最优雅的修复方法,但它有效,我找不到任何其他方法。

if ($arg == 'true' && isset($_SESSION['xyz']['noredirect'])) {
session_destroy(); 

} }

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

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