How to increase Laravel session and CSRF Cookies lifetime?

 By default Laravel have a very strong session cookies management system. By this thing you can manage the logging and many things. Even we can store some data temporary by using the cookies of session. but the Laravel have a limited life span of its session. And often this thing can be a barrier to manage the login state.

By default Laravel cookies session and it’s all other cookies are valid for 120 minute.

Change the Laravel default session or cookies lifetime


To change the Laravel cookies lifespan there are so many process developers are using. But I suggest people to use the .env file. Because this file is completely secure and Laravel declare on this fine about the session duration in minute.

By default cookies are in .env file is

SESSION_DRIVER=file
SESSION_LIFETIME=120

Change is as you want. But the lifetime should be in minute. After changing this lifetime, it will change the CSRF cookie lifetime also. So think about it also while you are changing the session life time.

Post a Comment

Previous Post Next Post