Nasser Ali Karimi
Nasser Ali Karimi

Reputation: 4663

Session expire time for each session

Can we set expire time for each session in Laravel?

If we can, how is it possible from the controller for each session that we create?

Upvotes: 9

Views: 58372

Answers (2)

Mohammed Shabeer k
Mohammed Shabeer k

Reputation: 287

Change the SESSION_LIFETIME= (duration in minutes) in the environment configuration.

Upvotes: 3

Jomoos
Jomoos

Reputation: 13083

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.

  1. Try if user exists in database
  2. If yes, and he is user who needs longer session lifetime, run config(['session.lifetime' => $newLifetime]);
  3. Log user in
  4. Enjoy longer session lifetime for current user

Source

You have to make the above changes in LoginController.

Upvotes: 29

Related Questions