PHP sessions *not always* working

2019-02-14 12:51发布

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.

标签: php session vps
4条回答
小情绪 Triste *
2楼-- · 2019-02-14 13:18

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.

查看更多
淡お忘
3楼-- · 2019-02-14 13:31

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楼-- · 2019-02-14 13:37

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.

查看更多
祖国的老花朵
5楼-- · 2019-02-14 13:41

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

查看更多
登录 后发表回答