homepage Welcome to WebmasterWorld Guest from 54.196.62.23
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Tracking visitors
adammc

10+ Year Member



 
Msg#: 3589737 posted 9:49 am on Mar 3, 2008 (gmt 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

 

jatar_k

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



 
Msg#: 3589737 posted 2:46 pm on Mar 3, 2008 (gmt 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

henry0

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



 
Msg#: 3589737 posted 2:55 pm on Mar 3, 2008 (gmt 0)

jatar_K,
in that case (AOL, AT&T etc.)
How could you ban a user?

jatar_k

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



 
Msg#: 3589737 posted 2:57 pm on Mar 3, 2008 (gmt 0)

you can't

especially when you think of proxies as well

coopster

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



 
Msg#: 3589737 posted 2:57 pm on Mar 3, 2008 (gmt 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.

adammc

10+ Year Member



 
Msg#: 3589737 posted 8:42 pm on Mar 3, 2008 (gmt 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?

adammc

10+ Year Member



 
Msg#: 3589737 posted 9:01 pm on Mar 3, 2008 (gmt 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");

cameraman

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3589737 posted 9:22 pm on Mar 3, 2008 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved