Increasing PHP session lifetime
If you are running a server using PHP, you're probably storing your session information using a cookie with a name of PHPSESSID. If you want to increase the lifetime of sessions on your server, you need to edit the php.ini file which is usually found in the /etc/ directory, but it may be different on your server.
Once you are editing the file, you want to find the parameter called session.cookie_lifetime and increase this value (which is in seconds). This will increase the lifetime of the cookie that your server writes to your user's browser.
You might think you are done at this point, most people do. But you're not. Although the lifetime of the cookie has been increased, you also need to increase the retention of the session information on your server. This information is stored in session-specific files on your server which are cleaned up by a garbage collection service that is very aggressive. By default, these files can be deleted after 20 minutes of inactivity. So even though the session cookie is still on the user's browser, there is no corresponding session information on the server so the session is essentially invalid.
To correct this you'll want to increase the value specified by the session.gc_maxlifetime parameter. I increase it to the same value as I set session.cookie_lifetime. This way I can be certain that the sessions really will last for that amount of time.
Once you make these changes, you'll need to restart your server for the changes to take effect.
Once you are editing the file, you want to find the parameter called session.cookie_lifetime and increase this value (which is in seconds). This will increase the lifetime of the cookie that your server writes to your user's browser.
You might think you are done at this point, most people do. But you're not. Although the lifetime of the cookie has been increased, you also need to increase the retention of the session information on your server. This information is stored in session-specific files on your server which are cleaned up by a garbage collection service that is very aggressive. By default, these files can be deleted after 20 minutes of inactivity. So even though the session cookie is still on the user's browser, there is no corresponding session information on the server so the session is essentially invalid.
To correct this you'll want to increase the value specified by the session.gc_maxlifetime parameter. I increase it to the same value as I set session.cookie_lifetime. This way I can be certain that the sessions really will last for that amount of time.
Once you make these changes, you'll need to restart your server for the changes to take effect.
| Rating: | 100% positive, 2 total Votes |
| Categories: | PHP server Apache |
| Added: | on Jan 23, 2009 at 12:04 pm |
| Added By: | an anonymous user |
| Searches: | server session php increase lifetime |

