PHP Session Stopped Working

老子叫甜甜 提交于 2019-12-25 07:24:10

问题


I've been using PHP sessions on a site I'm building and it's been working fine until strangely this morning:

One page one:

session_start();
$_SESSION['myarray']=$myarray;

Then on page two I try:

session_start();
print_r($_SESSION['myarray']);

however it shows an empty array.

I've checked on page 1 and the array has values in it.

Any ideas on what to look for to debug this?

Thanks.

(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!


回答1:


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'] and $myarray as same.

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.



来源:https://stackoverflow.com/questions/15572350/php-session-stopped-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!