Michdd Posted May 17, 2009 Share Posted May 17, 2009 How can I count the number of people viewing a page? These people won't be registered on the website. Is there a way to do this without using a session? And would I have to use a database? Quote Link to comment https://forums.phpfreaks.com/topic/158446-counting-the-number-of-people-viewing-a-page/ Share on other sites More sharing options...
RussellReal Posted May 17, 2009 Share Posted May 17, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/158446-counting-the-number-of-people-viewing-a-page/#findComment-835604 Share on other sites More sharing options...
Michdd Posted May 17, 2009 Author Share Posted May 17, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/158446-counting-the-number-of-people-viewing-a-page/#findComment-835613 Share on other sites More sharing options...
RussellReal Posted May 17, 2009 Share Posted May 17, 2009 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 } Quote Link to comment https://forums.phpfreaks.com/topic/158446-counting-the-number-of-people-viewing-a-page/#findComment-835618 Share on other sites More sharing options...
BobcatM Posted May 17, 2009 Share Posted May 17, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/158446-counting-the-number-of-people-viewing-a-page/#findComment-835619 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.