0

I have created one simple website for my client. Using Register and Login form with the session.

I want to maintain session after closing the browser, shut down the computer and reopen website after the 1 day. (No need to re-login).

I have already used below code for that but still not getting success.

setcookie('PHPSESSID',session_id(),60*60*24);
session.gc_maxlifetime = 1440
php_value session.gc_maxlifetime 7200
session.gc_maxlifetime=315360000
session.use_cookies=1
session.cookie_lifetime=315360000

Please guide me if any wrong from my side.

  • Possible duplicate of [How do I create persistent sessions in PHP?](https://stackoverflow.com/questions/9797913/how-do-i-create-persistent-sessions-in-php) – steros Jun 27 '18 at 06:47

1 Answers1

1

Setcookie expire argument is not a time value, it's a Unix value.
As you written the cookie should expire January 2 1970.
What you should do is use time()+60*60*24 if you want one day cookie lifetime.

Andreas
  • 23,610
  • 6
  • 30
  • 62
  • Thank you. :) It is working fine. setcookie('PHPSESSID',session_id(),time()+60*60*24); I did checked with setcookie('PHPSESSID',session_id(),time()+60); // For 1 mint. and it is working fine. – Dhirendrasinh DRC Jun 27 '18 at 07:13