bunlarda benim yazdığım kodlar.

$s = $_SERVER['HTTP_REFERER']; 
$bulu = array("http://","www.");
$degistiru = array("","");
$icerik = str_replace($bulu,$degistiru,$s);
$tag_bol = explode(".", $icerik);
$ref = $tag_bol[0];
$referer = "siteadresin"; // http:// - www - .com,net,org yazmadan gir.
if($ref == $referer) {
echo "";
}
elseif (!$ref) {
  echo ""; 
} else {
$adres = $_SERVER['HTTP_REFERER']; 
mysql_query("insert into referer SET adres='$adres'");
}