Home > Blockchain >  How to keep php session alive after closing browser
How to keep php session alive after closing browser

Time:08-22

I tried all the approaches but nothing is working

ini_set('session.gc_maxlifetime', 3600);
session_set_cookie_params(3600);
session_start();

CodePudding user response:

You need to change the lifetime of the cookie itself. Even if session persists on server, it won't work if the cookie is gone. Try setting session.cookie_lifetime as well:

ini_set('session.cookie_lifetime', 3600);
ini_set('session.gc_maxlifetime', 3600);

CodePudding user response:

While sessions can't be preserved after closing the browser, cookies are often what websites use to maintain data after a site has closed. In PHP, saving them looks like this:

// from https://www.w3schools.com/php/php_cookies.asp
setcookie($cookie_name, $cookie_value, time()   (86400 * 30), "/");
// and you can read it later like this
echo $_COOKIE[$cookie_name];
  • Related