Page 1 of 1

users online, sessions help

Posted: Fri Mar 17, 2006 12:21 pm
by anthony88guy
So I have a site, and I would like to display current users online. The current way I am accomplishing this is, I have a database with a sessionid, time, ip fields. Now when a user enters the site, a session is started and the sessionid, time and ip is entered into the database. I run a query selecting rows within the last 15mins. Sessions are destroyed when the browser closes.

My dilemma is that when you enter the site, and then end the session. Then re-visit the site (creating a new session) it counts that as 2 different users thus faking the users online count. Now what i could do is if the users ip = ip in database update that row, but what if you have multiple computers shared one ip?

One way I can think of but don't know how to create the query is select rows within last 15mins but with different ips.

Any ideas? Thanks.

Posted: Fri Mar 17, 2006 12:24 pm
by Burrito
15 minutes is a large gap.

I'd suggest using ajax to fetch users who are online in a more realtime fashion. You can key it off of an ID on a row. It might show dupes, but if you lessen the time for a 'refresh' the dupes won't show as long.

Posted: Fri Mar 17, 2006 12:27 pm
by anthony88guy
Burrito wrote:15 minutes is a large gap.

I'd suggest using ajax to fetch users who are online in a more realtime fashion. You can key it off of an ID on a row. It might show dupes, but if you lessen the time for a 'refresh' the dupes won't show as long.
My site doesn't receive must activity so i kept it large. I rather not use AJAX when i know it can be done with PHP and MySQL.

Posted: Fri Mar 17, 2006 12:30 pm
by Burrito
you could use a cookie then.

set it to expire in 15 mins....

Posted: Fri Mar 17, 2006 4:10 pm
by anthony88guy
Burrito wrote:you could use a cookie then.

set it to expire in 15 mins....
I don’t see the need to add additional stuff (lack of better word), when it could be done without.

Posted: Fri Mar 17, 2006 4:38 pm
by RobertGonzalez
Look at the system that phpBB uses to count its users online. phpBB uses sessions for logged in users as well, so it may be inline with what you want.

Posted: Fri Mar 17, 2006 4:40 pm
by Burrito
you've already pointed out that there's no way to uniquely identify users. You can't key it off of the ip address because multiple people could use the same IP. You don't want the same user shown twice and if they return within the 15 minute timeframe, they would.

the only solution I can see is to key it with the ip address in conjuction with the username (decreases the room for error, but error is still potentially there), or to use a cookie (which would be 100% (assuming the user can and will accept cookies)).

so in response to your last post, given the 'tools' you're using, it can't be done...you're gonna have to add more tools to your bag to accomplish what you're after.

Posted: Fri Mar 17, 2006 4:42 pm
by Burrito
with regards to Evarah's post:

phpBB uses a log in to generate the session, or a cookie (which essentially logs the user in again).

as I just said above, that's the only way you can do this.

Posted: Fri Mar 17, 2006 5:27 pm
by RobertGonzalez
Hey, that's what I do (sometimes). I have modified the phpBB code to my needs so it would do what the OP wants.