Welcome to WebmasterWorld Guest from 126.96.36.199
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
unique is a difficult thing to track
if not then the true number of unique is somewhere between the number of page views and the number of unique ips
// 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)")
$result = mysql_query("SELECT * FROM tracking WHERE pagename='$somepagename' and last_visit< CURRENT_DATE - INTERVAL 7 DAY");
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.