21, July 2008

users online - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: users online
« previous next »
Pages: [1] Print

Author Topic: users online  (Read 767 times)
Global Moderator
Internet Junkie
*****
Gender: Male
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?


Last blog : Are You Stumbling Yet?
Global Moderator
Internet Junkie
*****
Gender: Male
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...


Last blog : Are You Stumbling Yet?
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6279
38500 credits
Members referred : 374


It's time to use PHP5!


« Reply #2 on: Nov 02, 2006, 12:50:26 PM »

the easiest way is to store the data (ip address and time) in your database.

during the access of each page there need to be a check about the number of records in the last xx minutes.


Last blog : 4th of July Lottery from TemplateMonster.com
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
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.

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Internet Junkie
*****
Gender: Male
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?


Last blog : Are You Stumbling Yet?
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 7970
40777 credits
Members referred : 3



« Reply #5 on: Nov 03, 2006, 12:16:51 AM »

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? Smiley )

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1807
9006 credits
Members referred : 6



« Reply #6 on: Nov 03, 2006, 12:47:47 AM »

For now I'll just track the number of visitors by the IP address


Last blog : Are You Stumbling Yet?
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=4647
Tags : proxy databases Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: users online
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Jul 21, 2008, 01:11:34 AM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 35.669
Total Topics: 7.373
Total Members: 3.694
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: jinous@webdco.com

26 Guests, 4 Users online :

6 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.