doucheng1884 2014-07-02 12:10
浏览 110

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

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).

  • 写回答

2条回答 默认 最新

  • du9698 2014-07-02 12:22
    关注

    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... :)

    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)