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.
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.
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),
]
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:
In this tutorial, I will explain the laravel 9 image upload example. image or file upload is the most common task in web...
Feb-28-2022
In this article, we will see how to remove/hide columns while export data in datatables in laravel 8. When we are u...
Oct-13-2020
In this article, we will see how to create web notifications in laravel 9 using pusher. Here, we will learn how to...
Feb-03-2023
Hey there! I recently faced the need to upgrade my PHP version from 7.4 to the latest 8.0 on my Ubuntu server. It might...
Nov-06-2023