In this tutorial, we will discuss, how to increase session timeout in laravel 9. You will learn how to set session lifetime in Laravel 9. I would like to show you how to set session timeout in Laravel 9.
You can easily increase session lifetime in Laravel 5, laravel 6, laravel 7, laravel 8, laravel 9, and Laravel 10 versions.
If you want to increase your session lifetime then you can easily do it from the configuration file in Laravel. laravel provide session.php there is a ‘lifetime’ key option for setting time in minutes. in the session configuration file, there is an also several options for the set driver, timeout, expire_on_close and encrypt, etc.
Basically, you can not set lifetime sessions for forever but you can set in minutes for session expiration time. so I will set 1 year time for the session to expire.
60 * 24 * 365 = 525600
Here I will show how to increase the lifetime from the env file and configuration file. so let’s see both examples as below:
Here i will show how to increase lifetime from the env file and configuration file. so let’s see both example as bellow:
Solution 1: Using .env File
<?php use Illuminate\Support\Str; return [ ..... 'lifetime' => env('SESSION_LIFETIME', 120), ..... ]
Solution 2: Using Config File
<?php use Illuminate\Support\Str; return [ ..... 'lifetime' => 1 * (60 * 24 * 365), ..... ]
I hope it can help you….