There are many ways of detouring spammers from your website, but we have listed a few examples below using the popular programming language PHP and the htaccess file. If you know of any other methods feel free to submit them to us by email or using our contact form.
3 Ways of Stoping Referral Spam using PHP
PHP Example 1
if (strpos($HTTP_REFERER, 'http://') > 0)
{
$pieces=explode("/", $HTTP_REFERER);
$lookup = gethostbyname($pieces[2]);
if ($lookup == "81.15.90.85?)
{
syslog(LOG_ALERT,"redirected $pieces[2]");
header("Location: " . $HTTP_REFERER);
exit();
}
}
PHP Example 2
if(eregi("zwarecreations.com",getenv("HTTP_REFERER"),$regs)) {
print(" ");
exit;
}
PHP Example 3 Redirect spammer back
if (strpos($HTTP_REFERER, 'ttp://') > 0)
{
$pieces=explode("/", $HTTP_REFERER);
$lookup = gethostbyname($pieces[2]);
if ($lookup == "81.15.90.85")
{
syslog(LOG_ALERT,"redirected $pieces[2]");
header("Location: " . $HTTP_REFERER);
exit();
}
}
.htaccess Method
SetEnvIfNoCase Referer ".*(credit|texas-hold-em|holdem|badwordshere).*" BadReferrer
order deny,allow
deny from env=BadReferrer
The above code, you can use if you have mod rewirte enabled or installed in Apache.
Copy the following and past it in your .htaccess file
# Start Copying
#turn on the rewrite engine
RewriteEngine On
# block any access that has the word 'spammer' in the referrer URL
# the NC = no case, while the OR mean or (go to the next one)
RewriteCond %{HTTP_REFERER} ^http://(www\.)?.*(-|.)spammer(-|.).*$ [NC,OR]
# Append list of highly known spammers
RewriteCond %{HTTP_REFERER} (8k\.com) [NC,OR]
RewriteCond %{HTTP_REFERER} (8m\.com) [NC,OR]
RewriteCond %{HTTP_REFERER} (4t\.com) [NC,OR]
RewriteCond %{HTTP_REFERER} (send-?free) [NC,OR]
RewriteCond %{HTTP_REFERER} (canadianlabels) [NC,OR]
RewriteCond %{HTTP_REFERER} (s5\.com) [NC,OR]
RewriteCond %{HTTP_REFERER} (crepesuzette) [NC,OR]
RewriteCond %{HTTP_REFERER} (mortgage) [NC,OR]
RewriteCond %{HTTP_REFERER} (fidelityfunding) [NC,OR]
RewriteCond %{HTTP_REFERER} (houseofsevengables) [NC,OR]
RewriteCond %{HTTP_REFERER} (casino) [NC,OR]
RewriteCond %{HTTP_REFERER} (cialis) [NC,OR]
RewriteCond %{HTTP_REFERER} (viagra) [NC,OR]
RewriteCond %{HTTP_REFERER} (gambling) [NC,OR]
RewriteCond %{HTTP_REFERER} (credit-?card) [NC,OR]
RewriteCond %{HTTP_REFERER} (istarthere\.com) [NC,OR]
RewriteCond %{HTTP_REFERER} (gambling) [NC,OR]
RewriteCond %{HTTP_REFERER} (poker) [NC,OR]
RewriteCond %{HTTP_REFERER} (zwarecreations.com) [NC,OR]
RewriteCond %{HTTP_REFERER} (zerofunk.com) [NC,OR]
RewriteCond %{HTTP_REFERER} (mediavisor) [NC,OR]
RewriteCond %{HTTP_REFERER} (texas-?hold-?em) [NC,OR]
RewriteCond %{HTTP_REFERER} (commerce\.com) [NC,OR]
RewriteCond %{HTTP_REFERER} (istarthere\.com) [NC,OR]
RewriteCond %{HTTP_REFERER} (datashaping\.com) [NC,OR]
RewriteCond %{HTTP_REFERER} (newprinceton\.com) [NC,OR]
RewriteCond %{HTTP_REFERER} (xopy\.com) [NC,OR]
RewriteCond %{HTTP_REFERER} (webdevboard\.com) [NC,OR]
RewriteCond %{HTTP_REFERER} (devaddict\.com) [NC,OR]
RewriteCond %{HTTP_REFERER} (whiteguysgroup\.com) [NC,OR]
RewriteCond %{HTTP_REFERER} (guestbookz\.com) [NC,OR]
RewriteCond %{HTTP_REFERER} (webdevsquare\.com) [NC,OR]
RewriteCond %{HTTP_REFERER} (singles-?christian) [NC,OR]
RewriteCond %{HTTP_REFERER} (dating-?christian) [NC,OR]
RewriteCond %{HTTP_REFERER} (christian-?dating) [NC,OR]
RewriteCond %{HTTP_REFERER} (jewish-?singles) [NC,OR]
RewriteCond %{HTTP_REFERER} (sex-?meetings) [NC,OR]
RewriteCond %{HTTP_REFERER} (swinging) [NC,OR]
RewriteCond %{HTTP_REFERER} (swingers) [NC,OR]
RewriteCond %{HTTP_REFERER} (personals) [NC,OR]
RewriteCond %{HTTP_REFERER} (sleeping) [NC,OR]
RewriteCond %{HTTP_REFERER} (sleep-?disorders) [NC,OR]
RewriteCond %{HTTP_REFERER} (insomnia) [NC,OR]
RewriteCond %{HTTP_REFERER} (libido) [NC,OR]
RewriteCond %{HTTP_REFERER} (herbal) [NC,OR]
RewriteCond %{HTTP_REFERER} (enhancement) [NC,OR]
RewriteCond %{HTTP_REFERER} (sexual) [NC,OR]
RewriteCond %{HTTP_REFERER} (herbal-?sleep-?aid) [NC,OR]
RewriteCond %{HTTP_REFERER} (gabapentin) [NC,OR]
RewriteCond %{HTTP_REFERER} (melatonin) [NC,OR]
RewriteCond %{HTTP_REFERER} (sleep-?deprivation) [NC,OR]
RewriteCond %{HTTP_REFERER} (adult-?finder) [NC,OR]
RewriteCond %{HTTP_REFERER} (adult-?friend) [NC,OR]
RewriteCond %{HTTP_REFERER} (friend-?finder) [NC,OR]
RewriteCond %{HTTP_REFERER} (friend-?adult) [NC,OR]
RewriteCond %{HTTP_REFERER} (finder-?adult) [NC,OR]
RewriteCond %{HTTP_REFERER} (finder-?friend) [NC,OR]
RewriteCond %{HTTP_REFERER} (discrete-?encounters) [NC,OR]
RewriteCond %{HTTP_REFERER} (cheating-?wives) [NC,OR]
RewriteCond %{HTTP_REFERER} (housewives) [NC]
# at the end of your list, you want the following
# which gives them a 403 response
# if it's your last block in the .htaccess file, use [F,L] instead
# to let apache know you're done...
RewriteRule \.*$ - [F,L]
# Stop Copying
Using HTML Syntax NOFOLLOW
Change your links or just your statistics / referral log link to the following syntax.
<a href="http://your-site.com/statistics.html" rel="nofollow">Your Link</a>
The above HTML tag nofollow to fight spam, especially referral spam, is not a strong enough disincentive, but it's another alternative to help you battle spammers.
Tip: Useing the ROBOT.TXT file to detour Spamming!
Many sites statistics and referral log pages have been given a Google page rank, and because of this they have been indexed and targeted by spammers to get their "Spoofed HTTP REFERRAL," link in users logs. By using the ROBOT.TXT file you can disallow spider agents like Googlebot, Yahoo, Msn from cralling your referral or statistics pages. This will ensure that your statistic pages don't have a page rank and be less appealing to spammers.
How to disallow using Robot.txt file
User-agent: *
Disallow: /images/
Disallow: /scripts/
Disallow: /db/
Disallow: /statistics/
Disallow: /referrals/
Be sure to use your directory path and upload the robots.txt file in the < root directory > of your domain. |