[web] How do we know how many ppl online

Started by
7 comments, last by evolutional 19 years, 6 months ago
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 :)??
Ride the thrill of your life
Play Motorama
Advertisement
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.
have onload and onunload call a php that in-/decrements a counter.
8! bits.. wow..
I would have thought that variables were scoped locally to that connection only... Even for included php files...
www.aidanwalsh(.net)(.info)
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).
enum Bool { True, False, FileNotFound };
I'd say have a user database and see how many user sessions are on.
Rob Loach [Website] [Projects] [Contact]
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).
Of course I meant store your counter in a file..
8! bits.. wow..
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.

This topic is closed to new replies.

Advertisement