blufish Posted August 4, 2008 Share Posted August 4, 2008 Okay heres the idea, what I want to do is make it so I have a txt file that has a number that contains how many people are online at that time. I wanted to know if I would be able to change the number (and txt file) when someone quits the page if not, how is this to be achieved? Quote Link to comment Share on other sites More sharing options...
Stooney Posted August 4, 2008 Share Posted August 4, 2008 It's usually done using a database. When a user does an action, a field is updated with the current time. They are considered online for 5 mins after their last action. So each action they do, their last action is updated with the current time. If you wanted to do this with a text file, you would have to log a list of ip address and a time for each and use the same method. It wouldn't be as 'good' as using a database though. Quote Link to comment Share on other sites More sharing options...
.josh Posted August 4, 2008 Share Posted August 4, 2008 It doesn't matter whether it's database or flatfile, you'd have to keep track of info just the same. How you do that depends on what kind of system you have. Do users log in to show them "online?" Either way would involve their acct info. Does "online" to you mean simply being at your website? You're going to have to go by less reliable things like IP address, regardless of whether you do it with a flatfile or database. chrisdburns touched on a common method of determining online status. That is, you want to keep track of the time in which the user makes a page request, and then have a script check the last time a page was requested and if it's more than (for example) 5 minutes, then consider the user logged out. Why is it done this way? Because the server has no method to determine whether a user decides to go to some offsite page or close the browser or turn of the computer or any of that stuff. It doesn't know if the user is leaving for good or just going to the bathroom. Quote Link to comment 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.