Welcome to WebmasterWorld Guest from 23.22.182.29

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Tracking visitors

     
9:49 am on Mar 3, 2008 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 1, 2004
posts: 389
votes: 0


Hi guys,

I would like to create a script that logs the following so I can track 'unique' visitors to each product page on my online store. I assume I would use unique IP to determine this?

id - auto inc
page name - data generated from products page
visitor ip -
date / time of visit

I assume i need to do something like this:

// Check if visitor is already in the table for the certain page
$ipaddress = $_SERVER['REMOTE_ADDR'];
$visit_date = time();
$result = mysql_query("SELECT * FROM tracking WHERE ipaddress = '$ipaddress' AND pagename='$somepagename'");

How would I perform the rest of the query?
Also it would be nice to allow a visitor to appear in the table again as a unique if he revisits after 1 week, is that possible?

Any help would be greatly appreciated

2:46 pm on Mar 3, 2008 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 0


you can't rely on ip being a unique identifier of a single user, take AOL, anyone on AOL has the same ip as innumerable others.

unique is a difficult thing to track

are they logged in, logged in users can always be uniquely tracked. You could also use cookies, that would get the number closer to reality.

if not then the true number of unique is somewhere between the number of page views and the number of unique ips

2:55 pm on Mar 3, 2008 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member henry0 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 19, 2003
posts: 4388
votes: 2


jatar_K,
in that case (AOL, AT&T etc.)
How could you ban a user?
2:57 pm on Mar 3, 2008 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 0


you can't

especially when you think of proxies as well

2:57 pm on Mar 3, 2008 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12533
votes: 0


You really can't. Not without the chance of banning an entire IP block in a sense because if somebody else ends up with that dynamic IP address, you potential are blocking any given user at any given time because you never know who is going to have that IP address next time around.
8:42 pm on Mar 3, 2008 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 1, 2004
posts: 389
votes: 0


? what about setting a cookie then using IP?
Surely there must be a way I can roughly judge how many visitors my pages are getting using soemthing like my example above?
9:01 pm on Mar 3, 2008 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 1, 2004
posts: 389
votes: 0


Wouldnt something like this be appropriate?

Insert data....

// get the pagename
$page_name = $r['product_name'];

// get the date / time
$date = time();

// run the query
mysql_query("INSERT INTO tracking
ipaddress, page_name, date)VALUES(
'$ipaddress, '$page_name, '$date)")
or die(mysql_error());

View stats.....

$result = mysql_query("SELECT * FROM tracking WHERE pagename='$somepagename' and last_visit< CURRENT_DATE - INTERVAL 7 DAY");

9:22 pm on Mar 3, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Jan 16, 2007
posts:914
votes: 0


It would be better to use the session id.

I started with one written by someone called darklight - if you search for 'user tracker php script darklight' you'll run across it pretty quick. I've been using it for years with modifications along the way - looks like the author has put out a newer version than the one I have. When I downloaded it I had just barely started with php and didn't understand cookies at all. The script was well enough written that I could understand what was going on and modify to suit.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members