I am experiencing a strange problem when I try to get a session to persist for 100 days. I set the session to last for 100 days using the code below, but the session appears to last ~30 minutes only. One of the comments in PHP.net suggests updating a couple of ini settings (see first two lines of below code), but that still does not prevent the session from expiring prematurely. I also tried manually setting the expiration for PHPSESSID in addition to calling session_set_cookie_params(), but the session still expires early. I would be most grateful for any suggestions. Here is the code I am using:
Code:
ini_set("session.cache_expire","100*24*60*60"); // default is 180, which is 3 hours...
ini_set("session.gc_maxlifetime","100*24*60*60"); // default is 1440, which is only 24 minutes
$timeout100days = time()+100*24*60*60;
$timeoutToday = mktime('23','59','59', date('m'), date('d'), date('Y'));
$expire = time()-1800;
if (!empty($_COOKIE['login_temp']) && !empty($_COOKIE['PHPSESSID'])) {
if ('not_public_terminal' == ($_COOKIE['login_temp'])) {
setcookie('PHPSESSID',$_COOKIE['PHPSESSID'],$timeout100days, '/', 'kinostat.com');
session_set_cookie_params($timeout100days, '/', 'kinostat.com');
//echo('<p>login_temp cookie is \'not_public_terminal\', cookie params set to 100 days.</p>');
} else { // if login_temp is not FALSE
setcookie('PHPSESSID',$_COOKIE['PHPSESSID'],$timeoutToday, '/', 'kinostat.com');
session_set_cookie_params($expire, '/', 'kinostat.com');
//echo('<p>login_temp cookie is \'public_terminal\', cookie params set to 0 days.</p>');
}
} else { // if login_temp not set
if (!empty($_COOKIE['PHPSESSID']))
setcookie('PHPSESSID',$_COOKIE['PHPSESSID'],$timeoutToday, '/', 'kinostat.com');
session_set_cookie_params($expire, '/', 'kinostat.com');
//echo('<p>login_temp cookie is NOT SET, cookie params set to 0 days.</p>');
}