ItSolutionStuff.com

How to Increase Session Lifetime in Laravel?

By Hardik Savani • April 16, 2024
Laravel

Hi Dev,

This article goes in detailed 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 example of laravel increase session timeout.

You can easily increase session lifetime in laravel 5, laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 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....

Tags: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Laravel - How to Check If Array is Empty in Blade?

Read Now →

Laravel Clear Cache of Route, View, Config Command

Read Now →

How to Use Date Format Validation in Laravel?

Read Now →

How to Get Current Controller Name in View Laravel?

Read Now →

How to Set Config Value Dynamically in Laravel?

Read Now →

How to Get Config Variable Value in Laravel?

Read Now →

How to Configure Git Username and Email?

Read Now →

How to Check User Login or Not in Laravel?

Read Now →

How to Install and Run Laravel Project on Localhost?

Read Now →

Laravel Repository Pattern Tutorial Example

Read Now →

How to Get Query Strings Value in Laravel?

Read Now →