Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Nickbuds

dynamic visitor counter

This topic is 5593 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to make a dynamic visitor counter for http://www.javatutorials.org so that people can see how many people are on the site at that moment. How does one do this? Thanks for your help in advance. Nickbuds Webhost www.JavaTutorials.org Webdeveloper, WebSynergy AS Oslo, Norway thetutor@javatutorials.org

Share this post


Link to post
Share on other sites
Advertisement
You track a list of live sessions.

When a user first visits your site, you give them a unique ID (a session ID). This session ID gets passed from page to page, either in the post vars ("page.cgi?sessid=blah") or in the cookies.

Then, you need a database to keep track of the sessions. A table with ''session id'' and ''last request time'' would do fine.

When anyone requests any page, you check their session ID in the database. If it''s not there, you add it. Then, you set the ''last request time'' on it to the current time.

Then, when you want the number of current visitors, you prune the table - remove all session ids where the last request time is, say, more than 5 minutes ago; then, just get the number of records in that table.

Incidentally, PHP can handle all the session stuff for you, if you''re using it.

Superpig
- saving pigs from untimely fates, and when he''s not doing that, runs The Binary Refinery.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!