How to achieve to keep alive the session for long time.
Example: If I logged into a page and after sometime(say 5hrs) the session is getting closed automatically. How to make it alive until I press logout button.
How to achieve to keep alive the session for long time.
Example: If I logged into a page and after sometime(say 5hrs) the session is getting closed automatically. How to make it alive until I press logout button.
Use
ini_set('session.gc_maxlifetime', <seconds>);
in your php script that uses sessions
alternatively increase that value within your php.ini when you are server admin. But note that this is server wide.
To make it project / directory local you can also create a .htaccess file for your project containing:
php_value session.gc_maxlifetime <seconds>
but this may be restricted by the AllowOverride setting of the server
My suggestion is using cookies (with a disclaimer on the website!).
Try something like that, where time()+60*60*24*100
represents the validity of the cookie in seconds.
IMPORTANT: in order to let this work with the most recent chrome updates, don't forget the last NULL
parameter!
setcookie("your_cookie_name", $session, time()+60*60*24*100,'/', NULL);
Then, in order to use the cookie, just read it and save it in a new session:
if(!isset($_SESSION['your_parameter_name']) $_SESSION['your_parameter_name'] = $_COOKIE['your_cookie_name'];