How to Increase Session Lifetime in Laravel?

This article goes into detail on how to increase session timeout in laravel. you will learn how to set session lifetime in laravel. i would like to show you how to set session timeout in laravel 7. we will help you to give an example of laravel increase session timeout.

You can easily increase session lifetime in laravel 5, laravel 6 and laravel 7 version.

If you want to increase your session lifetime then you can easily do it from the configuration file in laravel. laravel provides session.php there is a ‘lifetime’ key option for setting time in minutes. in session configuration file there are an also several options for the set driver, timeout, expire_on_close and encrypt, etc.

Basically, you can not set a lifetime session forever but you can set in minutes for the session expiration time. so I will set 1 year’s time for the 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),
  
    .....
  
]

we hope it can help you….

0 0 vote
Article Rating

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x