I have a website which currently shows how many people are online in the last 2 minutes. However if a person has the site open in his browser but say he leaves the pc to get a drink, after 2 minutes, he is shown as being offline. Basically, you have to be clicking around the site to be shown as online. Could someone please help me in this dilemma! If I refresh the page every 2 minutes, this would be very annoying for the user. I'm not sure if I can refresh a single image every 2 minutes? Not sure if this would work. + rep for anyone that can help
You could insert a hidden iframe, and in this iframe is a page that refreshes every X amount of time. And this page updates the counter. Other than that, PHP cannot connect to the client and check if he's still online. And if you want to do it from the clients side to the server, you need either HTML or Javascript.
Thanks nico_swd, I'm going to try it out, seems pretty complicated though lol If they don't click any links of the site, after 2 minutes it will show them as being offline. Most of the time, people just go away for 5 minutes to get a drink or food, they would like to be shown as online. So other people can send the messages and talk to them.
hey, check this site out, i think their widget refreshs without refreshing the page http://whos.amung.us/showcase
I keep a lot of where users are going and when they hit a page, their browser info/ip address/timestamp are stored. So, I ask mysql who's timestamp is less than 10 minutes and I get a pretty good idea. To keep the log from being huge, cron prunes in once every 5 hours.
You need to set your timeout to longer period, to 5 or 10 minutes. It should be somewhere in your script, in the section where it records all the people online. It is probably time in seconds (120 for 2 minutes), so, you simply need to change that time to the value you need. Use 300 for 5 minutes, or 600 for 10 minutes. Good luck!~
KJeep track of the last active time in the database. To get the count just select records where the last active time is less than 2 minutes ago Hope this helps
This sounds like a job for AJAX. AJAX will send data to the backend server behind the scenes so your user doesn't have to refresh the page. I've used this for IM chat on my website, but it would be perfect for what you're doing. If you Google PHP and AJAX you'll find something easy.
Thanks joshhrob, I will try this out, never used AJAX before but from what I've heard its not that hard.