I am having problems with a PHP site where I start work when users log out after a few minutes (the exact time changes, but often enough to be a problem), regardless of whether they were active using the site or not.
The difficulty is that I cannot reproduce this problem, if I log in, when the same users use the same browser, I do not log out, which suggests that this is not the case when the site is completely broken. Unfortunately, I do not have access to user machines to run any traffic tracking software.
What I already checked is:
- Ask users to try different browsers. This does not seem to solve the problem and is not a long-term solution, since I cannot dictate which browser clients will use.
- Server time is correct and corresponds to user machines.
- The Apache user works the same way as he has write permission to the session folder, and I can see the created session files and the time of their modification.
- No output buffering functions are used.
- The problem occurs on different pages that seem to have nothing in common (i.e. not all of them use AJAX or update the database or for some other reason).
- Users only get access to their account from one computer, i.e. they don’t work on their laptop, switch to the desktop, and then wonder why they went to their laptop (we do not allow multiple simultaneous logins for the same user).
Session parameters in PHP are Debian defaults and have not been changed in the .htaccess file or elsewhere. The main ones are:
session.cookie_lifetime 0 session.gc_divisor 100 session.gc_maxlifetime 1440 session.gc_probability 0 session.save_handler files session.save_path /var/lib/php5 session.use_cookies On
Debian deletes sessions via the cron job instead of using the PHP garbage collector, so gc_probability is set to 0. The PHP version we are running is: PHP 5.2.6-1 + lenny13 with Suhosin-Patch 0.9.6.2 (cli) (latest version in Lenny, we'll get to Squeeze soon, but I don't think this is causing the problem.)
We use Zend_Session to manage sessions, and an instance of Zend_Session_Namespace is created once on each page, thus automatically calling session_start (). Sessions are cleared by calling Zend_Session :: destroy () on the exit page, so the only ways to exit the system are:
- If they explicitly click on the exit link (we register when this happens, and it seems that the page’s prefetching and thus the user’s registration are not visible).
- If they leave a session inactive for more than 24 minutes, Debian will probably delete its session at that point (there will be a cron job that every half hour will delete all sessions that have been unmodified for more than 24 minutes).
- If they close the browser, because their session cookie with the expiration of time 0 will be deleted.
Checks if a user is registered:
- They have a valid session (it is checked whether we can access $ zsession-> user_id).
- There is a row in the session table that has the corresponding user ID and session ID, and this was the last update less than an hour ago. We delete this line when we log out, so even if the session still exists on disk, no one can access this account without logging in.
Can anyone suggest other things that I can try?
Edit: some additional things I tried based on the comments on the left:
- Setting session.cookie_domain: This seems like a very strange behavior in PHP. If I do not set this variable and leave it as the default value '' (empty line), then a request to www.domain.com will trigger the cookie www.domain.com. However, if I set cookie_domain to "www.domain.com", the domain for the cookie will be ".www.domain.com" (note the leading dot, which means valid for everything below www.domain.com, for example, subsite .www.domain.com).
- Setting session.cookie_lifetime: PHP does not seem to update the expiration time for each request, so if I set cookie_lifetime to 3600, the cookie will expire one hour after the user's first visit to the site, even if they log in and use it constantly.
Edit 2: based on other things, people asked:
- The site is located in a data center in a separate VLAN. No one accesses a site on the same network as the site.
- IP authentication is not used, as well as the client IP address used in any part of the session (for example, we do not attach the session to the IP address and block the user if their next request comes from another IP).
pwaring
source share