search

Home  >  Q&A  >  body text

Laravel session expiration applies to each session.

Can we set expiration time for each session in Laravel?

If possible, how can we set the expiration time through the controller for each session we create? Thanks.

P粉547362845P粉547362845491 days ago382

reply all(2)I'll reply

  • P粉475126941

    P粉4751269412023-07-24 10:54:00

    Please change SESSION_LIFETIME= (duration in minutes) to the value in the .env file.

    reply
    0
  • P粉854119263

    P粉8541192632023-07-24 09:47:32

    You can change the lifetime of the session globally by changing the lifetime value in the config/session.php file:

    /*
    |--------------------------------------------------------------------------
    | 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 for each user, you need to set this value before the user logs in.

    You need to make the above changes in LoginController.

    reply
    0
  • Cancelreply