Reputation: 2288
I wanted to put in the login
page a checkbox "stay logged in".
That should never end the session of the user unless the user logs out.
I know that in app/config/session.php I have these variables:
'lifetime' => 60,
'expire_on_close' => false,
But I wanted to maintain alive the session forever, and not be removed if the user close his navigator.
Any ideas on how should I proceed? Thanks
Upvotes: 14
Views: 22541
Reputation: 919
Laravel has a built-in feature to remember users, I'd strongly recommend using it.
If you would like to provide "remember me" functionality in your application, you may pass a boolean value as the second argument to the attempt method, which will keep the user authenticated indefinitely, or until they manually logout. Of course, your users table must include the string remember_token column, which will be used to store the "remember me" token.
if (Auth::attempt(['email' => $email, 'password' => $password], $remember)) {
// The user is being remembered...
}
if you want to solve the problem manually, there is workaround for this: you have to set the expires date of your cookie to a date in the wide future, somewhat like 2050. this is technically not forever, but should usually be long enough.
Upvotes: 14
Reputation: 3541
You can set some big values. I have tried now at 7900 years
i.e, 365*24*60*7990 = 4152240000 minutes
'lifetime' => 4152240000
Upvotes: 3
Reputation: 163748
You can set lifetime
option to 35791394
. It's a maximum possible number for 32-bit machines:
'lifetime' => 35791394, // Session will expire in 68 years.
Upvotes: 7