问题描述
我在一个正在建立的网站上使用PHP会话,这一直很好,直到今天早上很奇怪:
I've been using PHP sessions on a site I'm building and it's been working fine until strangely this morning:
一页一:
session_start();
$_SESSION['myarray']=$myarray;
然后在第二页我尝试:
session_start();
print_r($_SESSION['myarray']);
但是它显示一个空数组。
however it shows an empty array.
我在第1页检查过,数组中有值。
I've checked on page 1 and the array has values in it.
有什么想法来调试这个?
Any ideas on what to look for to debug this?
谢谢。
(SOLVED):最终解决了这个问题 - 该行必须位于您使用任何会话的每个页面的顶部变量 - 字面上第1行!
(SOLVED): Eventually solved the problem - that line has to be at the very top of each page where you use any session variables - literally line number 1!
推荐答案
检查你的php设置是否有'register_globals = On'我认为是这样的。
当您的php设置中设置了register_globals时,它会将
Check if you have 'register_globals = On' on your php settings . I think this is the case.When you have register_globals set on your php settings, then it will treat the
$ _ SESSION ['myarray']和$ myarray视为一样。
$_SESSION['myarray'] and $myarray as same.
解决方案将禁用PHP中的register_globals,因为它在较新版本中已被弃用。
否则在$ _SESSION变量中使用不同的键名,或者将$ myarray变量更改为不同的名称。
Solution would be disable the register_globals in php as its deprecated in newer versions.Otherwise use different key name in $_SESSION variable or change $myarray variable to something different name.
这篇关于PHP会话停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!