In this article, we will see how to set a time limit for session in laravel 9. Here, we will learn to increase session lifetime in laravel 8 and laravel 9. We can not set session lifetime permanently but we can set in minutes for the session expiration time. So, here we will set 1 year time for the session to expire.
So, let's see session timeout in laravel 9, how to increase session timeout in laravel 8/9, laravel 9 set session expiration time, and laravel 9 session lifetime.
If you want to increase your session lifetime then we need to change it in the .env file and it is very easy to change it from the configuration file in laravel 8 and laravel 9.
Laravel provides you session.php file there is we can see the 'lifetime' key option for setting time in minutes.
In the session configuration file there is an also several options for set expire_on_close, encrypt, timeout and driver, etc.
Here, we will see a solution for increasing session timeout in laravel 9.
We need to define the value in minutes in the .env file as below.
<?php use Illuminate\Support\Str; return [ 'lifetime' => env('SESSION_LIFETIME', 120), ]
<?php use Illuminate\Support\Str; return [ 'lifetime' => 1 * (60 * 24 * 365), 'expire_on_close' => true, ]
Sometimes, happen cache issues. So, we need to clear it.
For clearing Cache, View, and Routes in laravel check the below link.
And, now your session timeout time will be increased.
You may also like: