Hey there. I've got a script that tracks user statistics and logs it to a file, and I've been trying to modify it to log all outside referrers to a file. When I say 'outside' I mean like google, yahoo, etc.. (right now it logs everything, including blanks for users without a referrer and every page that a user goes to on my site.)
With this code it will log everything:
function AddReferrer($time)
{
$file = "referrer.txt";
if (is_dir($this->AccessPath . "log/")) {
$fd = fopen ($this->AccessPath . "log/$file", "a+");
fputs ($fd, $this->Referer . "\n");
fclose ($fd);
}
} // end function AddReferrer
But when I try to exclude blank referrers and referrers that contain the name of my site nothing gets logged.
function AddReferrer($time)
{
// Begin new code
if (!empty($Referer)) {
$results = stristr($Referer, 'mysitename.com');
if ($results == FALSE) {
// End new code
$file = "referrer.txt";
if (is_dir($this->AccessPath . "log/")) {
$fd = fopen ($this->AccessPath . "log/$file", "a+");
fputs ($fd, $this->Referer . "\n");
fclose ($fd);
}
}
}
} // end function AddReferrer
Any ideas? It first checks to make sure that the variable $Referer is not empty, and if it's not empty, it makes sure that it doesn't contain 'mysitename.com'.
I've tried the '!empty()' code and the 'stristr() code with just regular variables and without the logging and the logic seems to work. So maybe there's a problem with parsing the $Referers variable?
Thanks for any ideas or help!