Server Side Storage Which is Browser Tab Independent

Is there a way with server side PHP in Wappler to save a value to a variable which:

  1. Will he retained between calls to different server actions.
  2. The values will be different between use of the app in different browser tabs
  3. Without needing to write the value to the database.

Why would you want to do that? Do you have all your users opening multiple tabs that needs to be behave as different users?

Can’t really imagine users doing that.

It is not possible, browser tabs share cookies and sessions, there is no way server-side to see that a request is coming from a different tab. Database and also client-side storage will not help you, they also are shared between tabs.

Only possible solution I can think of is that you do it on the client, generate or send the values to the client and the client keeps track of it and submits it to the server with each request to a server action.

You could set a unique ID on page load that is submitted with data and manipulate session to use an array. This, however would mean a user refreshing their page would lose anything that they were working on.

When a user starts an order process, could you not generate a record of a pending_order and save the details in the DB with a pending_orderid linked to their userid (for guests, you could store an id in the DB and in Local Storage to use as the user id so they could pick up between tabs if they are on the same browser)? That way a user could work on different tabs on different orders but also select a previous order they were working on. You would also probably get some pretty useful insights into which users are most active, products selected but not ordered, pain points where users stopped their order etc.

I have a booking form which my user’s clients may end up opening in different tabs to book onto different events at the same time… it is something I cannot control happening so I want to protect against them doing that and getting erroneous results!

Thanks for all your feedback folks!

Yes, I do already have a unique booking number available server and client side, so I will use that to manage what is happening!

A related question…

Is it guaranteed that client side browser session storage will be separate for each tab opened?

  • Opening a page in a new tab or window creates a new session with the value of the top-level browsing context, which differs from how session cookies work.

from: https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage

1 Like

Thanks @George!

The only other way I can think of is having a GET variable in the URL so each tab is recognised by that.

You should assume that users will make bad use of an app either on purpose or because they don’t know better. Sounds familiar?

If you think someone can send several forms when they should only send one you should control that on the server and forget about what users can do on their machines where you have absolutely no control.

I still don’t understand why you have this desire to push everything to the client. You seem to have this wrong perception that hitting the database is a bad thing and that it will tank your performance.

2 Likes

That’s exactly what I have!

1 Like

Wahey! Glad to be of some help :wink:

1 Like

I’m permanently scarred from my Bubble experience! :rofl:

1 Like

Surely by now you have noticed that you are not going to suffer the problems we all had in Bubble.

Also, have you taken into account that the more you push to the client-side the more you condemn users with low-spec computers?

Don’t underestimate your server :wink:

2 Likes

Don’t forget also that if the data is added to the DB it can be analysed - if it’s on the client, it can’t! Want to find the most commonly added to a basket, most commonly dropped before ordering, what stage users abandon orders…? It’s all useful to review and improve the app/site.