dynamic visitor counter
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
NickbudsWebhost www.JavaTutorials.orgWebdeveloper, WebSynergy ASOslo, Norwaythetutor@javatutorials.org
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.
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.
Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement