0

I have a log-in file with:

     ....
    $_SESSION['loggedin'] = true;
    $_SESSION['username'] = $username;
    $_SESSION['start'] = time();
    $_SESSION['expire'] = $_SESSION['start'] + (2592000);
    ...

And I have other file (when I log in correctly) with:

$now = time();
if($now > $_SESSION['expire']) ...

When I correctly enter an user and password from my database, I declare SESSION['EXPIRE'] with the aim of having the session expire within 1 month. I know this would work if I left the page open for 1 month. But if I close the browser and reopen it, SESSION['EXPIRE'] is not saved and therefore is automatically disconnected from the session. What can I do so that when I close the browser and reopen it, I still have the variable?

Cœur
  • 37,241
  • 25
  • 195
  • 267
LigaVirtual F1
  • 77
  • 1
  • 3
  • 6
  • 1
    since the cookie that contains the session id has no lifetime, it's deleted when the browser is closed. – Federkun Dec 12 '16 at 13:53
  • What can I do to prevent this happening? – LigaVirtual F1 Dec 12 '16 at 14:06
  • FWIW, trying to do something with sessions when the browser is closed is impossible with any amount of reliability and always the wrong approach to start with. – deceze Dec 12 '16 at 14:09
  • 2
    @Julian **Sessions use cookies**, and of course you can prevent them from being purged automatically on browser close **if you configure the cookies appropriately!** – deceze Dec 12 '16 at 14:09
  • → http://stackoverflow.com/questions/3684620/is-possible-to-keep-session-even-after-the-browser-is-closed – deceze Dec 12 '16 at 14:11

0 Answers0