Detect when the same window has been opened as in WhatsApp web

-2

I have a web platform created with php in backend and javascript in frontend, there is a file called configs.php, where only administrators can access (controlled by php sessions), the problem is that when two administrators access at the same time , catastrophic errors can occur. The idea is that only one administrator access configs.php at a time.

Then I need to detect when two users (administrators) have accessed that same section (configs.php), or even when the same user has opened two windows of that same section. In case this is detected, launch an alert that prevents configs.php from being used in more than one window at a time.

An example of what I need to achieve can be seen at web.whatsapp.com, where if they duplicate the window they are in, in the first window they had open, the following appears:

Then I need to achieve that with the technologies that I am using, maybe it can be done with javascript, or maybe it can only be done with php and the database (MySQL).

I accept solutions with Firebase Realtime Database, since I also use it on this platform and could implement it.

EDIT

I have not put code because the main thing I'm looking for with this question is to know if the technologies I'm using will allow me to achieve it, as well as being open to other possibilities, as some users have already answered.

Thank you.

    
asked by Roberto Sepúlveda Bravo 15.08.2018 в 06:56
source

2 answers

1

Create a table with 3 columns

index - INT AI url - varchar id_admin - INT

  • Each time an admin enters a page, it makes the query to    see if the url is in the list.

  • If the url is in the list then find out if id_admin is in zero

    • if it is zero updates the page and allows the admin to see it and manipulate

    • Always have a query to find out and compare the user's id active with the id_admin

    • If entering the value of id_admin is different from zero then it does not let that new admin see the page, redirect him or her javascript or as you prefer.

I do not know if the idea is clear, with this you will not allow more than 1 ID to see the page at the same time.

NOTE: Remember to pass ID_ADMIN to zero when the user logs off or changes pages.

    
answered by 15.08.2018 в 07:40
1

I recommend you do it with Pusher it's very easy to implement, you just register and it takes you by the hand in the implementation.

Once implemented what you need to control are the " Client events ".

The idea with pusher is basically to create a channel from the Frontend (Javascript) and listen to the events of the clients that connect, when connecting you can validate if another connected already exists and thus restrict access.

Greetings!.

    
answered by 15.08.2018 в 08:30