0

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 already 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.

user434366
  • 539
  • 7
  • 15
  • what does this mean: " I want to be able to know if someone or two people are on based on a mysql row." .. Do you want to limit ONLY TWO people on your application at a time OR do you want to know who is browsing your application at any time ? Both can be done, one involves session, other cookies – Stewie Sep 26 '10 at 15:48
  • Generally speaking, XMPP should automatically trigger an unavailable presence on behalf of the user when s/he has been "away" for an extended period of time. How long it would be depend on your session expiration settings on the server. This however may not 100% fit your purpose - Since there is ALWAYS a delay for that auto-unavailable presence to be sent (Again, the delay depends on your config.) However, using XMPP "just" for this purpose seems overkill. e.g. Have page visitors join a room, if it has 2+ users, leave automatically. You'll still run into race conditions however. – DashK Sep 28 '10 at 12:27

3 Answers3

2

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

bcoughlan
  • 25,987
  • 18
  • 90
  • 141
  • I do have xmpp setup so I don't have to do polling. I was wondering if there's another way without hammering the server – user434366 Sep 26 '10 at 15:59
1

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.

Community
  • 1
  • 1
David_001
  • 5,703
  • 4
  • 29
  • 55
  • So what happens when the browser crashes or when the connection goes down? – user434366 Sep 26 '10 at 16:11
  • @user434366: you can't do that without some form of callback (eg. ajax) telling the server every x seconds that the user's still on the page - which is fine as a solution. I've just pointed to an alternative solution which doesn't require polling, but would need some for of session timeout (to detect that the user hasn't done anything for 5 minutes, for example). – David_001 Sep 26 '10 at 16:25
0

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" ?

Ashwini Dhekane
  • 2,280
  • 14
  • 19