Global Moderator
Internet Junkie
Gender:
Posts: 1807
9006 credits Members referred : 6
« on: Nov 02, 2006, 12:11:11 PM »
I'm working on a new website and want to add a 'users currently online' message. What would be the best way to add this? I want something like: "currently 3 members and 10 guests online" The members state could easily be changed when the user logs in, but how would I track when the user exits the site?
Global Moderator
Internet Junkie
Gender:
Posts: 1807
9006 credits Members referred : 6
« Reply #1 on: Nov 02, 2006, 12:17:09 PM »
Just found
Code:
$_SERVER['REMOTE_ADDR']
So I guess I can add the ip address into a database along with a timestamp and delete all entries older than a certain amount of time. Then a simple record count on the table will show the number of visitors currently online. But I'm not sure how this would work if the users have the same ip address, like when 10 visitors access the page thru the same proxy, I want the counter to count 10 visitors and not just one...
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 7970
40777 credits Members referred : 3
« Reply #3 on: Nov 02, 2006, 04:17:47 PM »
The correct way to do this is to REPLACE instead of INSERT, and use ip2long($_SERVER['REMOTE_ADDR']) for the ips that are stored in the db. This way your app will be much faster.
Global Moderator
Internet Junkie
Gender:
Posts: 1807
9006 credits Members referred : 6
« Reply #4 on: Nov 02, 2006, 04:43:50 PM »
I've read about ip2long before, thanks for the reminder! So what about tracking several visitors comming thru the same proxy? I guess I'll have to work with session data then?
I've read about ip2long before, thanks for the reminder! So what about tracking several visitors comming thru the same proxy? I guess I'll have to work with session data then?
That's correct, but I wouldn't do it for a busy web site, as it would produce unessecery overhead to the system (after all how possible is to have many visitors from the same proxy at the same time? )