It´s possible to set session timeout by user in php?
Example: 2 users are registred in my site. I want that each user can set their own session timeout.
It´s possible to set session timeout by user in php?
Example: 2 users are registred in my site. I want that each user can set their own session timeout.
Yes, you can set a custom session timeout for each user. You can use the method as described in How do I expire a PHP session after 30 minutes? but store the absolute expiration time instead:
// set expiration time
$_SESSION['EXPIRES'] = time() + $customSessionLifetime;
// validate session
if (isset($_SESSION['EXPIRES']) && (time() < $_SESSION['EXPIRES'])) {
// session still valid; update expiration time
$_SESSION['EXPIRES'] = time() + $customSessionLifetime;
} else {
// session invalid or expired
session_destroy();
session_unset();
}
Here $customSessionLifetime
can be set differently for each user. Just make sure that its value is less than or equal to session.gc_maxlifetime and session.cookie_lifetime (if you use a cookie for the session ID).