简体   繁体   English

PHP会话副作用警告,全局变量作为数据源

[英]PHP session side-effect warning with global variables as a source of data

I'm trying to host a PHP web site that was given to me. 我正在尝试托管一个给我的PHP网站。 I see this warning: 我看到这个警告:

Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. 警告:未知:您的脚本可能依赖于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. 请注意,除非启用register_globals,否则会话扩展不会将全局变量视为数据源。 You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. 您可以通过将session.bug_compat_42或session.bug_compat_warn分别设置为off来禁用此功能和此警告。 in Unknown on line 0 在第0行的未知中

What does this mean? 这是什么意思? How might I track down the source of this problem within the code? 我如何在代码中追踪这个问题的根源?

basically you have a variable with the same name as your session. 基本上你有一个与你的会话同名的变量。 ex: 例如:

$_SESSION['var1'] = null;
$var1 = 'something';

which will reproduce this error. 这将重现此错误。 you can stop PHP from trying to find existing variables and warning you about them by adding these lines to your script: 您可以通过在脚本中添加以下行来阻止PHP尝试查找现有变量并向您发出警告:

ini_set('session.bug_compat_warn', 0);
ini_set('session.bug_compat_42', 0);

these values can be set in php.ini or .htaccess as well 这些值也可以在php.ini或.htaccess中设置

There seem to be a few problematic possibilities here: 这里似乎有一些问题:

http://www.spiration.co.uk/post/1231/Your-script-possibly-relies-on-a-session-side-effect http://www.spiration.co.uk/post/1231/Your-script-possibly-relies-on-a-session-side-effect

says that cases like this: 说这样的情况:

$_SESSION['firstname']=$_REQUEST['firstname'];

will trigger the warning. 会触发警告。

Additionally, I interpret this php bug content: http://bugs.php.net/bug.php?id=41540 to mean that this error may also occur when you assign a variable to the session superglobal that is not yet initialized, eg 另外,我解释这个php bug内容: http//bugs.php.net/bug.php?id = 41540意味着当你将一个变量分配给尚未初始化的会话超全局时也可能发生这个错误,例如

//Start of script
$_SESSION['bob'] = $bob;

This is good information on finding out what's causing the warning, but I would recommend NOT shutting off the warnings Owen mentions. 这是关于找出导致警告的原因的好信息,但我建议不要关闭Owen提到的警告。 These runtime functions are removed in PHP 5.4.0 and the developer should get into the practice of avoiding such usage of variables. 这些运行时函数在PHP 5.4.0中删除,开发人员应该开始避免使用这些变量。

To fix this, it may be a pain on the developers end, but if you have 要解决这个问题,开发人员可能会感到痛苦,但如果有的话

$_SESSION["user"]
$user;

rename the session to 将会话重命名为

$_SESSION["sessuser"];

Or vise-versa just as long as the session name and the variable name are different. 只要会话名称和变量名称不同,或者反之亦然。 Think of it this way: when you upgrade to the latest build, you'll have to debug your code anyhow. 可以这样想:升级到最新版本时,无论如何都必须调试代码。

When you are making changes to the .htaccess ini_set does not work. 当您对.htaccess进行更改时,ini_set不起作用。 You will need to do it as: 你需要这样做:

php_flag session.bug_compat_42 0
php_flag session.bug_compat_warn 0

in my case, php.ini change from on to off 在我的情况下,php.ini从on变为off

like this : 像这样 :

session.bug_compat_42 = off
session.bug_compat_warn = off

if not working, restart apache 如果不工作,重启apache

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

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