pascal_22 Posted August 29, 2014 Share Posted August 29, 2014 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 Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 29, 2014 Share Posted August 29, 2014 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! Quote Link to comment Share on other sites More sharing options...
CroNiX Posted August 29, 2014 Share Posted August 29, 2014 (edited) 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 August 29, 2014 by CroNiX Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted August 29, 2014 Share Posted August 29, 2014 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. 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.