开发者

php fails to store any _SESSION or _GLOBALS variable

I am storing a session and a global variable in file1.php. However, when I try to access those from file2.php I get nothing. I am using php 5.1.6.

开发者_高级运维$_SESSION['abc'] = $a;
$GLOBALS['def'] = $b;

Any idea?

Thanks in advance.


  • Do you have cookies enabled on your browser?
  • Are you remembering to call session_start at the top of BOTH pages?
  • Are you storing your session variables in $_SESSION ? Nothing else will store.

In regards to your edit: The variable stored in $GLOBALS is just a global to that script. You have to put the value in $_SESSION to use across pages.

Example:

// Page 1
session_start();
$_SESSION['abc'] = "hello world";
$GLOBALS['def']  = "More stuff.";

// Page 2
session_start();
echo $_SESSION['abc'];   // prints 'hello world'
echo $GLOBALS['def'];   // is not defined. Globals aren't session variables.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜