I have an Apache2 web server with PHP running on my Raspberry Pi and I'm using sessions for storing the user's ID when they log in. I noticed that when the browser closes, the session is destroyed. How do I make the session last longer (ideally forever until they log out)?
You can use a special setting of session_start() provided by PHP 7.0
... with the following setting the session
expires after 1 day
( 86400
seconds)... you can adjust this value as you want... even if you close the browser the session
persists, to terminate your session
you'll have to invoke session_destroy() ...
if (session_status() == PHP_SESSION_NONE) {
if (version_compare(PHP_VERSION, '7.0.0') >= 0) {
session_start(['cookie_lifetime' => 86400,]);
} else {
session_start();
}
}
I hope this helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.