I'm trying to build in a referrer tracker on our site, and I thought I had it all working, and it did work just as I intended it to for while. Then, for no apparent reason, I noticed that when I go to any page on the site, it's actually inserting 7 records into MySQL instead of just one.
For example, if I go to the home page, it will insert one record into the table, and then an additional SIX records with the index file as the referrer. Here's what a sample of the db structure and what's getting inserted:
ENTRY PAGE | REFERRER
/index.php | http://www.chisano.com/creative_services/index_tes...
/index.php | http://www.chisano.com/creative_services/index_tes...
/index.php | http://www.chisano.com/creative_services/index_tes...
/index.php | http://www.chisano.com/creative_services/index_tes...
/index.php | http://www.chisano.com/creative_services/index_tes...
/index.php | http://www.chisano.com/creative_services/index_tes...
/creative_services/index_test.php |
The creative_services page is what I clicked on. I'm using the include_once command for this little bit o' code:
// defining variables
$db_page = $PHP_SELF;
if(!isset($referrer)) { $referrer = $HTTP_REFERER; }
// inserting record to MySQL
$query = "INSERT INTO referrer_tracker (date_stamp, page, referrer) VALUES ('".time()."', '".$db_page."', '".$referrer."')";
$result = mysql_query($query, $connection);
print "I'm here";
I added the print I'm here line to see how many times that appears on the page, which it does only once. So how is the Insert statement executing multiple times??!
Any ideas?
Shaun