How To Increase Session Lifetime In Laravel
- In this small tutorial I will show you how to increase session timeout in laravel, in this example we can see how to set session lifetime in laravel.
- We can not set lifetime session for permanently but we can set in minutes for session expiration time. so here we will set 1 year time for session expire.
60 * 24 * 365 = 525600 // 1 year
- If you want to increase your session life time then we need to change in .env file and it is very easy to change it from configuration file in laravel. laravel provides you session.php file there is we can see ‘lifetime’ key option for setting time in minutes.In session configuration file there is a also several option for set expire_on_close, encrypt, timeout and driver etc.
- Here I will give you 2 solution for increase session timeout in laravel.
Solution 1: Using .env File
We need to define value in minutes in your .env file as below:
return [‘lifetime’ => env(‘SESSION_LIFETIME’, 120),
Solution 2: Using Config File
‘lifetime’ => 1 * (60 * 24 * 365),
In some conditions also happen Cache issue, So, we need to clear it.
For clearing Cache, View, Routes in Laravel check below.
And, Now your session timeout time will be increased…
Thanks For Reading !!