Check if the user is currently online (live)

I recently finished my application and I have a huge problem. I need to allow access to only one user at a time. For each user there is an index page available to each user and a "start" button. When the user presses the start button, application locks and other ppl must wait for the user to finish. When the user closes the tab / browser, the application should unlock automatically. Each user has 5 minutes to use my application. I partially solved my problem, but it still does not work properly - on each site I install a jquery script that every 5 seconds launches the extend.php file on the server (function $ .get ()). The php file modifies the time.txt file (it changes it to time () + 5), and the script on the intex site checks to see if (time ()>time.txt contents). Thus, when the application closes the tab / browser, the application is available. Obviously, my application is also session-based (when the user closes the browser, he loses access). On some computers, this just doesn’t work (it seems that jquery does not run the extend.php file, and this makes my application accessible all the time). So my question is: do you see any other ways to solve my problem?Do you see any other ways to solve my problem?Do you see any other ways to solve my problem?

Descr may be dirty, but I would like to describe everything strightforward;)

Sincerely.

+5
source share
4 answers

Try using the jQuery unload function so that when you click the close button, your web browser will execute the last line of the script before the user exits. Example:

$(window).unload(function(){

   "your php function to unlock the app here"

});

Hope this helps.

+2
source

Your method is fine, it should work. Yes, node.js or any other server-side javascript can be used to do the same, but when you run the script, this is the easiest solution. You really need to focus on researching which machines it doesn't work on.

+1
source

5 , 5 . jquery, , . , , . , time.txt () , , , . 1 .

+1

LOCK mysql, , .

, .

0

All Articles