PHP sessions *not always* working

2019-02-14 13:28发布

问题:

I've recently migrated a bunch of websites to a new VPS and I've been having a lot of trouble with PHP sessions. All the websites are pretty much configured the same way, but there is one website where the sessions don't always work. The thing that bugs me is it's kind of random. I can go on the website, log in, and the session will work fine. Then, I go back a hour later, try to log in on the same account, but it doesn't keep my session anymore.

The VPS is running on CentOS 5.8 and it has PHP 5.4.3. I should mention that before the migration, the website was running on PHP 5.3.

I have checked the session.save.path and it is fine. I can even see the session files (with the correct user and everything) but they are empty when the sessions are not working, which makes sense. But why does it sometimes work, and sometimes it doesn't? I'm having trouble figuring this one out.

回答1:

Sessions require server disk space to save has the server got disk space to save the session? we had a problem on a linux box where sessions stopped saving as its partition had run out of disk space.



回答2:

check your php.ini, do a phpinfo() and see how sessions are configured... look especially for the session.gc_maxlifetime setting.

http://php.net/manual/en/session.configuration.php



回答3:

We had this problem too. We solve it by changing session.auto_start = 0 to session.auto_start = 1 in the php.ini of the server. I don't know why but it solved our problem. We're still investigating why this worked and what are the consequences of doing this.



回答4:

I am also having the same issue sometime, with one of my dedicated server, which has PHP 5.4.3 installed.

Ironically, when I clear the browser cache(everything from beginning).

It works fine.



标签: php session vps