Forum Moderators: phranque
if(preg_match("/\.(cx$)¦(nu$)¦(by$)¦(to$)¦(st$)¦(pl$)¦(mn$)¦(bz$)¦(ru$)¦(cc$)¦(ki$)¦(br$)¦(us$)¦(de$)¦(md$)/i",$_SERVER['HTTP_REFERER'])){
header("Location: ".$_SERVER['HTTP_REFERER']);
}
The idea was they could eat up their own bandwidth if nothing else
Thanks Chris
First, "will this [prevent] referrer spam?" No, probably not. The reason is that log spammers 'fire and forget.' To begin with, their chances of log-spamming a site that makes its stats publicly-visible is pretty low. And second, many of the sites that do this are fairly low-tech sites. So, they crank out several hundred thousand requests, and if they get into one publically-published log or stats file, they are happy.
A few may notice your back-referral in their logs and take you off their URL-list, but it's probably not worth the bother.
My preferred approach for these guys is to internally rewrite the request to a subdirectory on my site. In that subdirectory is a .htaccess file that forbids access to any page in that subdirectory. It also contains an ErrorDocument directive that applies to requests in that subdirectroy only. The trick is that the custom 403 page is only 2 bytes long. In this way, my server sends the shortest practical 403 error response, and I go on about addressing more important problems.
You may have have an implied question as to whether your server's response was correct. If you'd prefer to use a 301-Moved Permanently redirect, then the following code change, lifted from the WebmasterWorld PHP forum, would write the 301 response:
if(preg_match("/\.(cx$)¦(nu$)¦(by$)¦(to$)¦(st$)¦(md$)/i",$_SERVER['HTTP_REFERER']))
{
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".$_SERVER['HTTP_REFERER']);
}
Jim
What really annoys me is the stats page was disabled months ago, but that doesn't make any difference to these idiots!
Two points to ponder:
Jim