Simple Referral Function for Your Website
This lil script saves the referrals to a text file. Each url will only be saved once, i.e it`s pretty Cool .
< ?
/*
This simple function can be regarded as Public Domain. You can do whatever you want, I do not require anything.
Change, distribute or sell this function, I do not care.
There is NO copyright.
*/// create a subdirectory "safeReferrals" relative to the script location and change the permissions to 777
$pathToFile = "safeReferrals/txt.txt";if (!empty($HTTP_REFERER)) {
safeReferral($HTTP_REFERER, $pathToFile);
}function safeReferral($referral, $pathToFile) {
$text = "";
$array = @file($pathToFile);
if (is_array($array)) {
for ($i=0; $i$text = $text.$array[$i];
}
}
if (!eregi($referral."\n",$text)) {
$text .= $referral."\n";
}
$fp = fopen($pathToFile, "w+");
fwrite($fp, $text);
fclose($fp);
}?>
March 24th, 2005 at 5:43 pm
I didn’t quite undestand what this script is used for. Maybe some more words on the subject of its functions and usability would be appreciated
March 24th, 2005 at 6:57 pm
well , it`s for getting a simple refferal stat , i.e to know which website/forum links to your site .
Say someone searches for “PHP” in google , this will show the URL from the search engine.
March 24th, 2005 at 7:23 pm
It`s cool , I modded a bit on my site :-p lol (hope you don`t mind).
It`s not showing up on myfree server though , let me have a look there.
Thanks :)
August 1st, 2005 at 6:29 pm
Its a cool script, but not always accurate if the proper referrer headers arent sent (depending on the HTTP). Also, for those that use Apache it does all the work for you - you can create a referrer log in your configuration file. You can then pull your stats from your servers log files (which can prove to be more accurate at times).
Regardless, I like your site and content!