Session在localhost上运行正常,但在webhost服务器上运行不正常

我编写了一个登录脚本,在我的测试服务器(localhost)上完全正常工作,但是当它没有用时 我将它上传到我的网站主机的网络服务器。</ p>

我已将其缩小到会话问题 - 成功登录后,会话设置成功,用户被重定向,但是 用户被重定向到加载的页面,会话显然已经消失。</ p>

我不想发布完整的源代码(但是),但这是它的逻辑:</ p>

login.php:显示表单,提交给self,检查user / pass并设置$ _SESSION ['loggedIn'] = true; 然后重定向到index.php </ p>

index.php:检查$ _SESSSION ['loggedIn'] == true(如果没有设置,或者为false,重定向回login.php)。< / p>

所以问题是当用户在登录并在login.php中设置会话后被重定向到index.php时,$ _SESSION ['loggedIn']甚至不存在。 / p>

有没有人知道什么可能会导致这样的事情? 网络托管服务器确实支持Cookie /会话</ strong> - 我做了一个非常简单的测试</ a >,它的工作原理,所以我想我的代码必须有一些...... :(但我真的不明白它,因为没有什么可以删除一个cookie(除了logout.php脚本)。</ p>
</ div>

展开原文

原文

I have written a login script that works perfectly fine on my test server (localhost), but it does not work when I upload it to my web host's web server.

I have narrowed it down to a problem with session - after successfull login, the session is set successfully, and the user is redirected, but when the page the user is redirected to loads, the session is apparantly gone.

I would prefer to not post the full source (yet), but here's the logic of it:

login.php: shows form, submits to self, check user/pass and set $_SESSION['loggedIn'] = true; then redirects to index.php

index.php: checks for $_SESSSION['loggedIn'] == true (if not set, or false, redirect back to login.php).

So the problem is that $_SESSION['loggedIn'] doesn't even exist when the user is redirected to index.php after successfully logging in and setting the session in login.php.

Does anyone have any clue on what could cause something like this? The web host server does support cookies/session - i made a very simple test, and it works, so i guess there must be something with my code... :( But I really don't understand it, because there's nothing that would delete a cookie (except for the logout.php script).

douyunhuan9886
douyunhuan9886 您是否允许来自远程域的cookie?PHP通常配置为将session_id存储在计算机上的cookie中,因此如果您不允许来自您的webhost域的cookie,则session_id将不会从login.php中存储,因此无法在index.php上调用。
6 年多之前 回复

2个回答



我已经调试了2个小时,和往常一样,我在写了一篇关于它的长篇文章后发现了问题。 。: - / </ p>

无论如何,问题是我在session_start()之前包含了一个class.db.php文件; </ strong>
我想,对于某些人来说 原因是,该文件输出在远程服务器上执行时不可见。 也许这是编码问题?</ p>

无论如何,我只是将session_start()移到了包含该文件之上,现在一切正常......:)</ p>
</ div>

展开原文

原文

I've been debugging this for 2 hours, and as usual, I find the problem right after writing a long post about it... :-/

Anyway, the problem was that I included a class.db.php file right before session_start(); I guess, that for some reason, that file output something invisible when executed on the remote server. Maybe it's encoding issue?

Anyway, I just moved session_start() above inclusion of that file, and everything works fine now... :)

dongpu5600
dongpu5600 无论如何。 下次来这里时,请提供一些代码。 只有逻辑没有多大帮助。 谢谢!
6 年多之前 回复



您在从客户端登录后更改了服务器日期,因此会话已过期,只需从客户端计算机清除历史记录。</ p>
< / DIV>

展开原文

原文

you changed the server date after login from client hence session expired, just clear the history from client computers.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐