Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if user open two tabs for same session?

Tags:

php

tabs

session

I've done a booking application done using CakePHP which involves a few steps before the checkout page. In between these steps I store the information in the session.

How it works is that Step 1 requires them to fill in their information. When going to Step 2, the information in Step 1 will be saved into the session object. As they proceed in the other steps, the process repeats. At the end when they checkout, all the data is then saved to the database.

Everything works great if the user opens one instance of the application in the browser. But once they have another page or another tab opened for the same application in the same browser, problem happens.

Let's say they have two instance of the application open in Tab A and Tab B. In Tab A they entered the details in Step 1 and proceed to Step 2. Then the user does the same thing in Tab B.

At the last step when the user does a checkout, information in Tab A is the same as in Tab B.

Right now, I can only think the best way is to prevent the user from opening the same application in two browser instance.

Is there a way to detect and prompt the user to complete the booking form in Tab A first when they try to open another instance in Tab B?

like image 993
darnpunk Avatar asked Apr 07 '11 01:04

darnpunk


2 Answers

1.The same problem (and solution) : https://sites.google.com/site/sarittechworld/track-client-windows

2.You can send information by POST or GET

like image 164
pufos Avatar answered Oct 24 '22 00:10

pufos


You could mark a session as started when step 1 is first started. Make sure server-side that they follow the right steps (i.e. they don't return to step 1 after step 1 has been completed unless they specifically click a link to do so.) Basically, track their current step on the server and update it as needed. In the event the user does something unexpected, you could give them the option to start over.

I'm wondering if hidden fields with timestamps on your forms might help. Kinda the same idea though.

Caveat: this process might break the essence of your browser's back button. I hate myself for letting that happen in one of my projects.

For cross-browser support, you'd need to have it associated with a user account or something that persists.

like image 22
Guttsy Avatar answered Oct 24 '22 00:10

Guttsy