In this tutorial you will learn about the How to Set or Increase Session Lifetime in Laravel and its application with practical example.
In this How to Set or Increase Session Lifetime in Laravel I will show you how to set or increase the session timeout or session lifetime in your laravel project. In laravel the session-timeout defines the default session timeout interval for all sessions. The session timeout is defined in minutes. In this tutorial you will learn following topics:
- How to Set or Increase Session Lifetime in Laravel
- What is default session time in laravel?
- How does laravel session expire?
How to Set or Increase Session Lifetime in Laravel
In laravel if you want to set session lifetime for 1 year you can do this as following:
1 |
60 * 24 * 365 = 525600 |
How to Set or Increase Session Lifetime in Laravel
Using .env File
1 |
SESSION_LIFETIME=525600 |
If you set the session timeout in the .env file. The config directory has a session.php. In this file, the session timeout of your laravel web application is set in this way.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?php use Illuminate\Support\Str; return [ ..... 'lifetime' => env('SESSION_LIFETIME', 120), ..... ] |
Using Config File
O open config/session.php file and set session timeout as following:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?php use Illuminate\Support\Str; return [ ..... 'lifetime' => 1 * (60 * 24 * 365), ..... ] |
What is default session time in laravel?
The cookie_lifetime specifies the lifetime of the cookie in seconds which is sent to the browser. The value 0 means “until the browser is closed.” Defaults to 0.
How does laravel session expire?
If you want laravel session to immediately expire on the browser closing then set that option. | */ ‘lifetime’ => 4320, ‘expire_on_close’ => false, if you want to set session lifetime per user, you need to set this value before logging in the user.