Laravel session expire time for each session
32,794
Solution 1
You can change the session lifetime, application wide by changing the lifetime
value on config/session.php
:
/*
|--------------------------------------------------------------------------
| Session Lifetime
|--------------------------------------------------------------------------
|
| Here you may specify the number of minutes that you wish the session
| to be allowed to remain idle before it expires. If you want them
| to immediately expire on the browser closing, set that option.
|
*/
'lifetime' => 4320,
'expire_on_close' => false,
Now, if you want to control the session lifetime per user, you need to set this value before logging in the user.
- Try if user exists in database
- If yes, and he is user who needs longer session lifetime, run
config(['session.lifetime' => $newLifetime]);
- Log user in
- Enjoy longer session lifetime for current user
— Source
You have to make the above changes in LoginController
.
Solution 2
change the SESSION_LIFETIME= (duration in minutes) @ env
Comments
-
Nasser Ali Karimi over 2 years
Can we set expire time for each session in Laravel?
If we can how it possible from the controller by each session that we create? Thanks.
-
Admin about 6 yearsis that per user? or the whole site?
-
Jomoos about 6 years@rtfm If we change it in the configuration file, it will be for the whole site. If we change it in
LoginController
as outlined in the above 4 steps, it will be per user.