我有 2 个页面:login.php 和 index.php。两个页面都以
开头session_start();
当我设置
$_SESSION['user'] = "name";
在 login.php 中打开 index.php,我的 session 对象是空的。怎么会?
编辑:
我发现了问题:IE 7。我不得不访问我的域。但是,我认为 session 存储在服务器上,而不是客户端上?比为什么我有 IE 盛大访问我的域? ( http://www.pcwindowstips.com/2007/09/04/how-to-enable-cookies-in-internet-explorer-7/ )
最佳答案
I thought a session is stored on the server, instead of the client? Than why do I have IE grant access to my domain? (http://www.pcwindowstips.com/2007/09/04/how-to-enable-cookies-in-internet-explorer-7/)
session 的工作方式是为站点存储 session cookie,其中包含您的 session ID。服务器知道你是谁的唯一方法是在每次加载页面时读取 session ID cookie。每个用户的所有 $_SESSION 数据都存储在服务器上,但必须为服务器设置 cookie 以知道要检索哪些 $_SESSION 数据。
这也是为什么如果您获得他们的 session ID cookie,您基本上可以“成为”另一个用户。
关于PHP session 在 PHP5 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/878756/