Jump to content

Counting the number of people viewing a page


Michdd

Recommended Posts

well, other than a session, some AJAX or a refreshing iframe every 15 minutes to tell your server they're active, and every 15 minutes clear ppl who havn't updated in 15 minutes, but sessions would most likely be better

well, other than a session, some AJAX or a refreshing iframe every 15 minutes to tell your server they're active, and every 15 minutes clear ppl who havn't updated in 15 minutes, but sessions would most likely be better

So you're saying to use AJAX and a database? Inserting people who are there, then removing them if they're not there the next check?

well, if they're not there.. than AJAX won't trigger, then they wouldn't get removed.. use ajax to keep updating the timestamp in teh database, and another time as the start time of the server, just make the table have 4 fields

 

ip | randomly_generated_number | last_active | server

 

and IP would be ofcourse their IP, randomly generated number would be a number randomly generated by the page, to know that they are the person who should be accessing that db entry, last active would be a simple timestamp, server would be true or false, being your server or not

 

set server to some number in the past, and then do a query every request from the ajax

 

like

 

if (mysql_fetch_array(mysql_query('SELECT * FROM `table` WHERE `server` = true AND `last_active` < (UNIX_TIMESTAMP(NOW()) - (60 * 15))'))) {

  mysql_query('DELETE FROM `table` WHERE `last_active` < (UNIX_TIMESTAMP(NOW()) - (60 * 15)) AND `server` = false');

  // clear up table

}

Just run a check every 5 minutes like Russell mentioned to check if they are active. Something like setup a php script that will retrieve your count() and echo it. Then if you wanted have a JavaScript call that php script in whatever time you designate. By using AJAX you would be able to retrieve the value echoed from your php script in the JavaScript variable.

 

 

Hope that makes sense.

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.