Jump to content

[SOLVED] Change number when someone leaves


blufish

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.