gpt4 book ai didi

PHP session 扩展不考虑全局变量

转载 作者:可可西里 更新时间:2023-11-01 00:51:48 24 4
gpt4 key购买 nike

我目前遇到错误:

Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively in Unknown on line 0

我相信它与以下代码有关(因为那是我开始注意到它的时候):

session_start();                         // Open sessions
$remember_alert = $_SESSION['alert']; // Remember session alert
session_unset(); // Unset all data in session
session_destroy(); // Kill empty session
session_start(); // Re-open session
$_SESSION['alert'] = $remember_alert; // Recall session alert

这是我正在构建的 CMS 的 logoff.php 页面上的代码,用于清除除 alert 变量之外的所有 session 信息。任何见解将不胜感激!

最佳答案

Hi, I had the same problem, and in mycase it was here $arrFormData and here$_SESSION['arrFormData'] The thing ishaving the same variable name. In mycase it happened on a $_GET array,but I guess it should be similar. Giveit a try on renaming the $arrFormDatavariable to something else and let usknow if it worked.

Source .

这是因为在某处你的变量名与全局 $_SESSION 的键相同。

例子

session_start();
$_SESSION['a'] = 1;
$a = 1;

您可以通过在 php.ini 中关闭 session.bug_compat_42 或使用 ini_set() 来禁用错误。

关于PHP session 扩展不考虑全局变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5616397/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com