views:

297

answers:

2

What is the best script to use for showing the current visitors or guests Online?

Thanks!

+1  A: 

I think it all depends on how your tracking who's online within your application.

Usually, when someone logs-in, you create a session for them that you could iterate through based on whatever language you are using.

You have to keep in mind that HTTP is a stateless environment, so determining when someone is online is largely subjective as to your opinion as to how long ago they logged in.

Ryan Smith
+2  A: 

As @Ryan Smith suggested, this greatly depends on the implementation details of the website. I'm sure that there is a off-the-shelf framework offering a storefront application with all the bells and whistles (such as the types of scripts you are mentioning); however, these can range anywhere from being free and open source, or very expensive.

Implementing a script like this yourself isn't very difficult. Assuming that you're keeping track of the users on the website in some form of data store (typically a backend database) you could do something like this:

  • When the page loads, fire a JavaScript that makes an Ajax request
  • Have the page that's the target of the Ajax request select a count of the number of rows in the table storing the active users. Return this result.
  • When the request completes, have the Ajax callback insert the number into the DOM in whatever place you'd like.

You can set this process to repeat at certain intervals so that the pages containing the script are dynamically updated showing a relatively up to date count of the number of users online.

Tom