0

可能重复:
Firefox 会话 cookie

我有这个代码

session_start();

$_SESSION['login'] = "bla";

var_dump($_SESSION);

$_SESSION['login'] = "bla";如果我在 Firefox 中执行此页面,然后从脚本中删除此行,然后关闭并重新打开浏览器,Firefox 会显示:["login"]=> string(3) "bla"

也就是说,firefox 在关闭浏览器后保存会话数据。为什么会这样?

PS这仅在Firefox中发生,其他浏览器都按预期工作,即结果是空数组。

4

2 回答 2

0

Firefox cannot save $_SESSION. $_SESSION is entirely a server side variable. It does not come to Firefox except that it will set a session cookie which is used only by php to find out the right user session on the server.

The reason you have been getting the ["login"]=> string(3) "bla" is because you had set it in the first run. Do this:

First run the script

session_start();

$_SESSION['login'] = "bla";

var_dump($_SESSION);

Then delete the $_SESSION['login'] = "bla"; line from the script and run it. It should still show that login key is set in session variable. Then run a separate script:

session_start();

$_SESSION['login'] = null;
// OR 
// unset($_SESSION['login']);

var_dump($_SESSION);

Then try to see the value of the Session variable and the value of 'login' key would be gone.

What I mean to say is: if you set something in the session, it will persist and you do not have to set it everytime the script runs. TO remove the value from session variable, you have to explicitly remove it.

于 2012-12-16T14:38:00.573 回答
0

您确定您正在测试脚本的正确版本吗?您可能希望在测试脚本中添加其他内容以确保例如显当前时间。

这里可能出现的一种情况是浏览器的所有实例共享同一个 cookie jar。为了强制浏览器删除会话 cookie,您必须关闭所有窗口和选项卡。这在“现实生活”中从来都不是问题,但是当您似乎无法退出时,它常常让开发人员发疯!

于 2012-12-16T14:05:45.450 回答