Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ManoMahe's avatar

How to keep previous form page with input data after session out due to inactivity & re-login in Laravel 9

Hi there!

I want to make my Laravel 9 project to easier for my users by keep the previously opened form/page to be reload again as it was, which had been redirected to login page because of session timeout due to inactivity.

Another scenario I want to handle the CSRF token also need to be refreshed, after the re-login on one browser tabs need to re-activate all other opened tabs with CSRF. Detailed example below, If I opened my project in 2 browser tabs (tab A, tab B). I filled tab A form inputs partially which is a ajax form and haven't used both the tabs for around 2.5 hours(SESSION_LIFETIME=120 already set & waited for that time to exceeded) and I refreshed the tab B then done re-logged in with the same user account.

After that I filled the tab B form balance inputs and pressed submit button returns me 419 -Page Expired or csrf token mismatched errors, which makes the data loss on the tab A

Could someone help me to how can I achieve this in Laravel 9?

0 likes
4 replies
Tray2's avatar

I can only think of two ways to do this

  1. Add the information to the session and read it from there.
  2. Use the browsers local storage.
1 like
ManoMahe's avatar

@Tray2 Yeah... I also thought the same but when we are mistakenly logged out in tab-B will clears all of our session inputs data, right? that's why still I have being confused to choose that.

Thanks for the local storage suggestion of The JS localStorage will helps me to store the previous active tab-B URL which will works after the session logged out and do re-login. But it will not easily helps me to resume the tab-A works where I left with CSRF token. I need to wildcard my all ajax URL in the App\Http\Middleware\VerifyCsrfToken, which I don't want to do so.

Tray2's avatar

@ManoMahe You could also use some kind of ajax call to keep the session alive, to prevent the logout, or you could automatically save the state of the form for the user.

ManoMahe's avatar

No, I don't want to prevent the logout process, just wanted to resume the form editor of tab-A job as it is with CSRF token too, when I re-logged in on another tab-B.

I'm convincing myself to got this to work by making wildcard of the URL in App\Http\Middleware\VerifyCsrfToken. B'coz, I don't get a clear feature flow in Laravel 9 to make this flow easier to develop.

Thanks for your time @Tray2

Please or to participate in this conversation.