问题
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