I'm not really sure how I would implement this along with a fair amount of security. I want to be able to know if someone or two people are on based on a mysql row. These two people are totally anonymous. I do have an xmpp server set up but I'm not sure how that would integrate into the mysql and I al开发者_开发问答ready have a separate login system for it. Server side is done with PHP
Edit: I want to ONLY allow two people on a certain page and that is it. But, if they leave the page I need to determine if they have left.
The issue is that if somebody closes their browser you have no way of being notified that they have left the page.
What you could do is have an AJAX request on the page, so that every 10-15 seconds it sends a request to the server containing a session id. Log the timestamp and the session id in a table, and you can then query the database to see what requests have been made in the last 15 seconds
You could try a solution using the OnBeforeUnload event, to notify you that a user has left the page, see best way to detect when user leaves a web page.
When you say "page" you are talking about browser-side-validation, because browser should be able to tell you that the user is still on that page. If you are trying to do this then you need AJAX like waitforatrain's comment. But there are some loopholes:
1) what if browser has javascript disabled?
2) what if user is inactive after loading the page? Should the page be kept "alive" ?
精彩评论