会话变量消失
我有一个会话变量的问题,当我导航到新页面时,该变量就消失了。 在页面 a 上,变量一直有效。我从头到尾已经做了几个输出。
在页面 B 上,它消失了,页面 b 看起来像这样:
<?php
session_start();
//include "dbConnect_local.php"; // Databasanslutningen lokalt
//include "dbConnect.php"; // Databasanslutningen web
echo $_SESSION['coming_from_input']." apa";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="sv" lang="sv" >
<head>
</head>
<body>
</body>
</html>
页面 b 与页面 a 位于同一域中。这就是所有代码,在 session_start() 之前没有发送任何内容;
使用 session_id() 我可以看到两个页面上的会话 id 不同。
感谢您的帮助
I have a problem with a session variable that just disappears when i navigate to a new page.
On page a the variable works all the way. I have made several outputs of it from start to finish.
On page B it is gone and page b looks like this:
<?php
session_start();
//include "dbConnect_local.php"; // Databasanslutningen lokalt
//include "dbConnect.php"; // Databasanslutningen web
echo $_SESSION['coming_from_input']." apa";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="sv" lang="sv" >
<head>
</head>
<body>
</body>
</html>
Page b is on the same domain as page a. And this is all code, nothing is sent before session_start();
Using session_id() I can see that the session id is different on the two pages.
Thanks for any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你确实有一个session_start();首先在 A 页上,不是吗?
如果是这样,也发布页面A,因为我们的信息太少了......
You do have a session_start(); on page A before everything else, don't you?
If so, post page A too, because we have too few info...
...并且您已检查日志以查看没有报告任何错误?
您已经创建了一个脚本,该脚本明确地抛出错误来检查您的日志记录是否正常工作?
您是否已经查看了 HTTP 响应标头以确保服务器在页面 A 上设置了 cookie?
您已经查看了 HTTP 请求标头来检查浏览器是否返回了 cookie?
您正在使用默认的会话处理程序吗?
并且您已检查会话文件目录是否可由网络服务器 uid 写入?
您是否已经检查过,在点击页面 A 后,会在该目录中创建一个包含预期内容的会话文件?
...只是你在原来的帖子中没有说。
...and you've checked your logs to see that no errors were reported?
And you've created a script which explicitly thows an error to check you're logging is working correctly?
And you've looked that the HTTP response headers to ensure that the cookie is being set by the server on page A?
And you've looked at the HTTP request headers to check that the cookie is being returned by the browser?
And you're using the default session handler?
And you've checked that the session file directory is writeable by the webserver uid?
And you've checked that after hitting page A a session file is created in that directory with the expected content?
...only you didn't say in your original post.
好吧,我现在已经解决了这个问题,看来是我愚蠢的网络酒店把事情搞砸了。我写这个作为答案而不是评论,以便每个人都可以看到。我确实是这样的:
我在页面a和页面b上写下了会话ID。它们不具有相同的价值。我认为这很奇怪,因为它在我页面的另一部分(登录和注册)中工作。所以我登录并从注册页面直接跳到这个问题的B页面。 Id:s 匹配。
好吧,有趣的是,所以我从页面 a 中删除了所有不需要的代码。当我现在尝试一切正常。很好,我逐块添加代码并一直在浏览器中运行代码,以查看它何时停止工作。
当我添加所有以前删除的代码时......它仍然有效!
我不知道事情是怎么变成这样的,但我猜是网络酒店把我的事情搞砸了。前几天与他们就其他问题进行了交谈,他们似乎在服务器上缓存了文件,所以当我上传新文件时,直到 10 分钟后我才能看到结果,那时我已经完成了另外 10 或 15 次上传......
Ok so I have solved this now and it seems to be my stupid webhotel that is screwing things up for me. I wrote this as an answer and not as a comment so that everyone could see it. I did like this:
I wrote out the session id on page a and page b. They did not have the same value. That's weird I thought, since it works in another part of my page(login and register). So i logged in and from the register page I jumpt directly to page B from this issue. Id:s were matching.
Ok funny, so I removed all code that wasn't needed from page a. When I now tried everything worked. Good, I added code chunk by chunk and ran the code in the browser all the time, this to see when it stopped working.
When I had added all previously removed code... it was still working!!
I have no idea how it came to be like this but my guess is that it's the webhotell screwing things up for me. Had a talk with them the other day related to other issues and it seemed like they cache files on the server so when I upload new files I could not see the results until 10minutes later, and by that time I had done another 10 or 15 uploads......