How To Increase Session Lifetime In Laravel

Websolutionstuff | Jun-28-2020 | Categories : Laravel PHP

In this article, we will see 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 sessions permanently but we can set in minutes for the session expiration time.

So, let's see laravel set session expiration and how to set session timeout in laravel 6 and laravel 7, and how to set session lifetime in laravel.

So, here we will set 1 year time for the session to expire.

60 * 24 * 365 = 525600 // 1 year

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. laravel provides you a session.php file there 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 give you two solutions for increasing session timeout in laravel.

Solution 1: Using .env File

We need to define the value in minutes in your env file as below.
.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),
  
]

In some conditions also happen Cache issue, So, we need to clear it.

For clearing Cache, View, and Routes in Laravel check below.

And, Now your session timeout time will be increased.

 


You might also like:

Recommended Post
Featured Post
How To Create Zip File In Laravel 7/8
How To Create Zip File In Lara...

In this tutorial I will give you example of how to create zip file in laravel 7/8. Some times client's have requirme...

Read More

Dec-17-2021

How To Get Client IP Address In Laravel 10
How To Get Client IP Address I...

In this article, we will see how to get a client's IP address in laravel 10. Here we will learn about retrieving the...

Read More

Apr-07-2023

How to Generate QR Code in Node.js
How to Generate QR Code in Nod...

In this example we will see how to generate QR Code in Node.js application. In this example we will use qrcode npm...

Read More

Sep-20-2021

How To Get Current Route In React JS
How To Get Current Route In Re...

As a web developer using React JS, I've come to appreciate the power and efficiency of this JavaScript library. Its...

Read More

Aug-11-2023