2 ways to increase Session Lifetime in Laravel explained step by step

    By: Thad Mertz
    2 years ago

    how to increase session timeout in laravel.


    This article explains how to increase session timeout in laravel. you will see how to set session lifetime in laravel. we would like to show you how to set session timeout in laravel 6,7 and 8. so lets see example of laravel increase session timeout.

    It can be done easily increasing session lifetime in laravel 5, laravel 6, laravel 7 and laravel 8 version.

    So If you want to increase your session life time then you can do it from configuration file in laravel any version (6,7,8). laravel provides "session.php" file there is a 'lifetime' key option for setting time in minutes. In session configuration file there is also several option for set driver, timeout and encrypt etc.

    Basically, we cannot set lifetime session for forever, but you can set in minutes for session expiration time.

    so we will set 2 year session expire time.


    2 year
    
    60 minutes
    
    24 hours
    
    365 days
    
    2* 60 * 24 * 365 = 1051200
    
    We calculated menutes in 2 years.
    


    Now we have minutes in 2 years the we can use method 1.


    Method 1 for increasing session in Laravel


    Go to application root directory and open ".env" file, there you can define session value

    SESSION_LIFETIME=1051200
    


    Method 2 for increasing session in Laravel


    For this you can edit config file. For that go in "config/session.php". There you can set value like this

    <?php
    
    ....  
    
    return [
    
    
        ....
      
    
        'lifetime' => 2 * (60 * 24 * 365),
      
    
        ....
      
    
    ]
    

    Like and comment.