简体   繁体   中英

Session works fine on localhost, but not on webhost server

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

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

您从客户端登录后更改了服务器日期,因此会话已过期,只需清除客户端计算机上的历史记录即可。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM