How many people on page?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

How many people on page?

Post by GeXus »

This may be a simple question, but how do you determine how many people are accessing a given page at a given time?

It's important that the number is accurate, so I don't want to set sessions that expire, and assume 30 minutes or something along those lines. But rather, the exact number of people that are accessing a particular file/page at a given time....

Any direction would be huge! Thank you.
buckit
Forum Contributor
Posts: 169
Joined: Fri Jan 01, 2010 10:21 am

Re: How many people on page?

Post by buckit »

The only real way is to use sessions. you can use javascript/ajax to run a php script that kills the session when the window closes... but that greatly determins on the browser settings.

Unfortunately there is no 100% accurate way... php is server side and the user leaving your site is client side. javascript is the only way to make the 2 sides talk.
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: How many people on page?

Post by cpetercarter »

A possible way is to keep a count (in a database) of unique IP addresses of visitors - deleting records more than, say, 1 hour old - and then make some heroic assumption such as that IP addresses which have requested one of your pages within the last 5 minutes are 'online'.
Post Reply