Now, let's see post of how to set session timeout in laravel 7. This article will give you simple example of laravel increase session timeout. In this article, we will implement a laravel increase session lifetime. you can see laravel set session expiration.
You can easily increase session lifetime in laravel 5, laravel 6 and laravel 7 version.
If you want to increase your session life time then you can easily do it from configuration file in laravel. laravel provide session.php there is a 'lifetime' key option for setting time in minutes. in session configuration file there is a also several option for set driver, timeout, expire_on_close and encrypt etc.
Basically, you can not set lifetime session for forever but you can set in minutes for session expiration time. so i will set 1 year time for session expire.
60 * 24 * 365 = 525600
Here i will show how to increase lifetime from env file and configuration file. so let's see both example as bellow:
Solution 1: Using .env File
you can simple define value in minutes in your env file as bellow:
.env
SESSION_LIFETIME=525600
config/session.php
<?php
use Illuminate\Support\Str;
return [
.....
'lifetime' => env('SESSION_LIFETIME', 120),
.....
]
Solution 2: Using Config File
config/session.php
<?php
use Illuminate\Support\Str;
return [
.....
'lifetime' => 1 * (60 * 24 * 365),
.....
]
I hope it can help you....
Do you like below Tutorials ?
- PHP Laravel 5.5 - import export data into excel and csv using maatwebsite
- Laravel 7.x and 6.x create custom facade example from scratch
- Node JS - Get Real time online users counter using socket io example
- PHP Laravel 7.x and 6.x - Bootstrap Admin Theme Integration example from scratch
- MySQL Query - How to select records of today to next Sunday ?
- Laravel 7.x and 6.x - username custom validation example
- Laravel 5.5 - Import Extract zip file using chumper/zipper package
- PHP Laravel Set Custom Validation Error Messages Example