0

I want my users to be logged in for a period of one week without having to log back in again. I implemented the solution on this page How to change the session timeout in PHP? but it is not working. I still get logged out after a period of inactivity (not sure how long, but often, at least a few times a day).

ini_set('session.gc_maxlifetime', 604800);
session_set_cookie_params(604800);
ob_start(); 
session_start();
$now = time();
if (isset($_SESSION['discard_after']) && $now > $_SESSION['discard_after']) {
    session_unset();
    session_destroy();
    session_start();
}
$_SESSION['discard_after'] = $now + 604800;
JamieTom
  • 101
  • 2
  • 14
  • Isn't this helpful? https://stackoverflow.com/questions/9797913/how-do-i-create-persistent-sessions-in-php – Eliâ Melfior Nov 16 '18 at 18:10
  • @EliâMelfior - Well, I think what that article is saying is to set the cookie lifetime, but I am pretty sure that is what this line of code is doing... session_set_cookie_params(604800) – JamieTom Nov 16 '18 at 18:40
  • Just in the time since I wrote this until now I went back to the site and was logged out. – JamieTom Nov 16 '18 at 19:44

0 Answers0