[web] How do we know how many ppl online
Is there an easy php script to know how many ppl online on your site ?
I found one tutorial but it uses database and all.. isn't there anything simpler :)??
You going to need to have a database unless there is some php code that you can see how many sessions you site has open, but you need to have sessions in your site to do that too.
I would have thought that variables were scoped locally to that connection only... Even for included php files...
What does "connected" even mean? If I hit your main page, am I "connected"? For how long?
The best way is probably to track the user using a cookie, and store a copy of that cookie in a database with a last-seen-time. Each time you get the same user back, you update the database entry last-seen-time for that cookie (and perhaps increment a visit counter). Seeing "active users" is then as easy as selecting the count of cookies that have a last-visit-time from 10 minutes or go or newer (for whatever value of "10 minutes" you prefer).
The best way is probably to track the user using a cookie, and store a copy of that cookie in a database with a last-seen-time. Each time you get the same user back, you update the database entry last-seen-time for that cookie (and perhaps increment a visit counter). Seeing "active users" is then as easy as selecting the count of cookies that have a last-visit-time from 10 minutes or go or newer (for whatever value of "10 minutes" you prefer).
Counting the number of active sessions is probably the cheapest way to do it. Another way would be to have a database that records the last time a session hit a page then use some maths to say <10mins == active. I'd personally go with the active sessions as you can change the session timeout to be lower if you need ot (at least you can in ASP).
You wouldn't need to if your server has an application dictionary, like ASP.
It'd then be a case of setting up a function in the global.asa file (for ASP) to increment an Application("VisitCounter") variable on Session_OnStart and decrement it on Session_OnEnd. I'm sure PHP has this functionality too.
It'd then be a case of setting up a function in the global.asa file (for ASP) to increment an Application("VisitCounter") variable on Session_OnStart and decrement it on Session_OnEnd. I'm sure PHP has this functionality too.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement