Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check whether user is currently online (live)

Tags:

jquery

php

I've recently finished my application and I've got a huge problem. I need to allow only 1 user to access it at a time. There is an index page accessible for every user everytime and "start" button. When user clicks start, the application locks and other ppl need to wait until the user finishes. When the user closes tab/browser, the application has to unlock automatically. Each user has 5 minutes to use my app. I partially solved my problem, but it still doesn't work properly - on every site I set the jquery script that every 5 seconds triggers "extend.php" file on the server ($.get() function). The php file modifies time.txt file (it changs it to time()+5) and the script on the intex site checks whether (time()>time.txt content). So that when the uses closes tab/browser, the app is accessible. Obviously my app is also based on sessions (when the user closes browser, he loses access). On some computers it simply doesn't work (it seems jquery doesnt trigger extend.php file and it makes my app accessible all the time). So my question is: do you see any other ways to solve my problem?

The descr might be messy but I wanted to describe everything strightforward ;)

Regards.

like image 935
02446 Avatar asked Oct 09 '22 06:10

02446


2 Answers

Try using an a jQuery unload function so that when they click the close button your web browser executes one last line of script before the user exits. Example:

$(window).unload(function(){

   "your php function to unlock the app here"

});

Hope this helps.

like image 145
Kevin Avatar answered Oct 13 '22 11:10

Kevin


Your method is OK, it should work. Yes, node.js, or any other server side javascript can be used to do the same, but having a script triggered is by far the easiest solution. You really should focus your time to investigate further on what machines it is not working.

like image 40
Nick Handerson Avatar answered Oct 13 '22 12:10

Nick Handerson