Jump to content

Count the online members/visitors


pascal_22

Recommended Posts

Hello to all!

 

I ask myself the following question: Is there a way that is better to calculate the number of members / guests online 
 
I have a table with  ip, id member ,URL of the actual page  ... 
I try with a primary key for the IP address, but some provider changes the IP Adress of their client several times a day or every few minutes ... 
So that resulted resulted duplicates entry... 
 
I try with the member id ... but that can not count visitors as those not connected their id is -1 
 
Is there a better way than another? 
 
Do You calculate just members connected? 
 
thank you 
 
pascal
Link to comment
Share on other sites

How do you create entries in this table?  How do you get rid of entries when  user is not logged in?  How do you know they didn't just close their browser and appear to be still online?  This was a topic a couple of weeks ago on some forum and there are a lot of issues with trying to keep track of who is online and who is not.  Did you figure out a way to do just that?  Love to see your code!

Link to comment
Share on other sites

We use a last_activity field that gets autoupdated whenever the user does something. Then we just look for users active in the last x minutes to determine who is online. Obviously not 100% accurate, but avoids some of the problems that ginerjm refers to.

last_activity timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
Edited by CroNiX
Link to comment
Share on other sites

Checking the status of a registered member is obviously different from checking the status of a guest. For registered members, the “only” challenge is to notice when they're no longer active. For guests, you also run into the typical problems like unreliable IP addresses, unreliable cookies etc. Personally, I don't try to track guests, because it's a lot of trouble for very little relevant information.

 

To check the status of a registered user, you usually want a combination of JavaScript and plain HTTP:

  • Every n seconds, JavaScript sends a “heartbeat” to the server via Ajax. If the last heartbeat is older than n seconds, then the user has appearently left the site. Note that JavaScript may or may not be active, so it's not enough to rely on this feature.
  • The log-in and every subsequent request update a timestamp. This gives you the last actual activity, but it also serves as a backup in case JavaScript is turned off.
  • When the user explicitly logs out, they're obviously no longer active.
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.