How to make a session last for 4 hours even if the page is not accessed? I tried using
ini_set('session.gc_maxlifetime',14400);
and
ini_set('session.cookie_lifetime', 14400);
like this:
ini_set('session.cookie_lifetime', 14400);
session_start();
but both won't work. I tried reading PHP SESSION but there's just a lot of information to take and I've tried several options already but to no good.
Edit: Now I've tried:
$hours = 4; //How long sessions last
$sessionCookieExpireTime=$hours*60*60;
// php.ini setting required for session timeout.
session_save_path('http://www.samplesite.com/');
ini_set('session.gc_maxlifetime', $sessionCookieExpireTime);
ini_set('session.gc_probability', 1);
ini_set('session.gc_divisor', 1);
session_set_cookie_params($sessionCookieExpireTime); /*Set the session parameters and start session*/
session_start();
then after validation:
setcookie(session_name(), $_COOKIE[session_name()], time() + 14400, "/");
It now shows that it will expire after 4 hours if I check the cookie data on my browser (not "When the browsing session ends") but if I leave the page inactive and get back to it after like an hour, it's not working as it logs me out. What is going on?