Current 'Online Users' Script

What's the best script to use to show current visitors or guests online?

Thank!

0


source to share


2 answers


As @Ryan Smith suggested, this is highly dependent on the implementation details of the site. I'm sure there is an out-of-the-box infrastructure offering a showcase app with all bells and whistles (like the types of scripts you mention); however, they can range from free and open source, or very expensive.

Injecting a script like this is not very difficult. Assuming you are tracking users on a website in some kind of data store (usually a database), you can do something like this:



  • When the page loads, run JavaScript which makes an Ajax request
  • On the page where the Ajax request is made, select the number of rows in the table that store active users. Return this result.
  • When the request is complete, ask the Ajax callback to insert the number into the DOM wherever you want.

You can set this process to repeat at regular intervals so that pages containing the script are dynamically updated to show a relatively fresh count of the number of users online.

+3


source


I think it all depends on how you track who is online in your application.

Usually when someone logs in, you create a session for them that you can iterate over based on whatever language you use.



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

+1


source







All Articles