Hi i'm new to programming but am currently working on a session timeout problem. Basically my session keeps timing out even though i've changed the session.gc_maxlifetime.
I think another script using the same directory to store session data which doesn't have the maxlifetime set, is running and thus it'll use the shorter value instead. TO combat this i've altered the htaccess file but it is still terminating after an 1hr 30mins, i need it to last for longer. My htaccess file is below. I've looked at and tried many of the relevant posts on this board but nothing has worked so far. Any ideas would be greatly appreciated.
SetEnv PHPRC /home/rocket/public_html/php.ini
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
<IfModule mod_php5.c>
php_value session.save_path "new/username/php_sessions"
php_value session.gc_maxlifetime "86400"
php_value session.cookie_lifetime "86400"
</IfModule>
# END WordPress
PHP doesn't do with session cookies what you might think it does...
php_value session.gc_maxlifetime "86400"
This merely sets the time after which garbage collection may occur - since there's only a very small chance that the session data will be garbage collected after this time this is unlikely to be the culprit.
php_value session.cookie_lifetime "86400"
This sets the time at which the session cookie expires... but it doesn't update at session_start()
therefore, if you start the session on one page, that sets the clock ticking. Moving from page to page won't reset the "clock" so a session with a cookie_lifetime
of 600 will expire 10 minutes after it was started not after 10 minutes of inactivity - you may be seeing this behaviour.
Your best bet is to set php_value session.cookie_lifetime "0"
this means that the session cookie will expire only when the user closes their browser.
If you want to handle an arbitrary expiry that triggers after a period of inactivity it's best to do that in the PHP code by setting a variable within the session, something like $_SESSION['expires']
and checking/updating/handling that at the start of every page.