I would like to set my sessions to last for 2-3 days so that my users will not have to login to get data after days of being idle.
Please help me with the code to achieve this.
I would like to set my sessions to last for 2-3 days so that my users will not have to login to get data after days of being idle.
Please help me with the code to achieve this.
You could try:
ini_set('session.gc_maxlifetime', 2*60*60*24); // 2*60*60*24 = 2 days
<?php
$value = 'something from somewhere';
setcookie("TestCookie", $value);
setcookie("TestCookie", $value, time()+3600); /* expire in 1 hour */
setcookie("TestCookie", $value, time()+(3600*24*2)); /* expire in 2 days */
?>
Do not increase session time for a huge amount of time.
Instead you can use the remember me cookies for your purpose.
You can create a cookie to store user name and password set the time for cookies life time to 2 or 3 days.
Whenever user enter your site check for existence of these cookie if they exists log in them backgroundly and redirect them on landing page.
Whenever the logout delete these cookies as well.
You can do by,
ini_set('session.gc_maxlifetime', 2*60*60*24); //2 days
But as session will destroy as soon as your user close the browser alternate you can use cookies
.
setcookie("TestCookie", $value, time() + 2*60*60*24);