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

hannanstd's avatar

laravel session conflict (important bug)

hi consider you have multiple browser tabs. and you have one form on each tab. then you click submit button of all form in all tabs very fastly (submit all forms in each browser tab together). and we redirect user in contorller with back()->withInput(). then when we redirect to back, we see inputs of some forms conflict and there is the data of some forms in other forms. how can i fix this bug?

Laravel Framework 6.18.35

0 likes
8 replies
Snapey's avatar

yes, session is shared between tabs. To not have this you would need to login separately in each tab.

Its not a security issue since each form is owned by the same user

hannanstd's avatar

it is not reasonable. becasue a user (operator) opens multiple tab and prepare some form and after prepared completely, he saves all forms and then this problem will be occure.

Sinnbeck's avatar

So how would you suggest that the data is stored instead if not in the session? Remember that laravel has no way of knowing that you have 2 tabs open. I have a feeling that the developers of laravel wont see this as a bug :)

automica's avatar

@hannanstd this behavior isn't specific to Laravel either.

The wider question is why your users are launching multiple browser windows to fill out your form. is it because the form is too complex?

hannanstd's avatar

@automica

Senario:

browser tab1: /product/edit/1

browser tab2: /product/edit/2

you want to edit title field in form in tab1 and tab2 and add suffix that there is in clipboard.

control+v in tab1 and save form1. Immediately control+v in tab2 and save form2.

then after get response in tab1 and tab2, If internet speed be slow, you can see the data of two forms are exactly similar! because ->withInput() uses session.

Snapey's avatar

Don't return with input. Redirect back to the edit page and reload the data.

thewebartisan7's avatar

Maybe you can try with MessageBag, see https://laravel.com/docs/7.x/validation#named-error-bags

return redirect('register')
            ->withErrors($validator, "productError{$productId}");

Then in view:


{{ $errors->{"productError$productId"}->first('email') }}

I never do this before, so not sure what is result. But maybe you can test. I think it should works, as long for each tab there is only 1 product. In case you want also allow multiple tabs with the same product, you have to adjust MessageBag unique id. Via javascript there is a way to get the tab id, see https://stackoverflow.com/questions/11896160/any-way-to-identify-browser-tab-in-javascript So you could for example store in cookie the tab id and attach to MessageBag.

Please or to participate in this conversation.