Forum Moderators: coopster

Message Too Old, No Replies

Block referrer

         

flashwebb

1:44 pm on May 23, 2006 (gmt 0)



Hi
i use this php-code to cupture bad spider bots
and i have been hit with lot's of referrer spam
wich i stop with isapi-rewrite for IIS..so now to my question
This is one of my referrer spammer and you can see they like this link very much (/modules.php name=4ndvddb&rop=show_dvd&id=108)
90 % of my logg show that link..so now i wonder by using the php-code below..if i can bann every visitor who are requesting this link
(/modules.php name=4ndvddb&rop=show_dvd&id=108)and be added to blacklist.txt file

2006-05-23 04:48:52 GET /modules.php name=4ndvddb&rop=show_dvd&id=108 - 210.182.198.181 HTTP/1.0 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1) damn.spammers 200 64 0

Code start#

<?php
if(phpversion() >= "4.2.0") {
extract($_SERVER);
}
?>
<html>
<head><title> </title></head>
<body>
<p>There is nothing here to see. So what are you doing here?</p>
<p><a href="http://www.altavista.se/">Go home.</a></p>
<?php
$badbot = 0;
/* scan the blacklist.dat file for addresses of SPAM robots
to prevent filling it up with duplicates */
$filename = "blacklist.txt";
$fp = fopen($filename, "r") or die ("Error opening file ... <br>\n");
while ($line = fgets($fp,255)) {
$u = explode(" ",$line);
if (ereg($u[0],$REMOTE_ADDR)) {$badbot++;}
}
fclose($fp);
if ($badbot == 0) { /* we just see a new bad bot not yet listed! */
/* send a mail to hostmaster */
$tmestamp = time();
$datum = date("Y-m-d (D) H:i:s",$tmestamp);
$from = "webmaster@yourdoman.com";
$to = "webmaster@yourdomain.com";
$subject = "ALERT: BAD ROBOT";
$msg = "A bad robot hit $REQUEST_URI $datum \n";
$msg .= "address is $REMOTE_ADDR, agent is $HTTP_USER_AGENT\n";
mail($to, $subject, $msg, "From: $from");
/* append bad bot address data to blacklist log file: */
$fp = fopen($filename,'a+');
fwrite($fp,"$REMOTE_ADDR - - [$datum] \"$REQUEST_METHOD $REQUEST_URI $SERVER_PROTOCOL\" $HTTP_REFERER $HTTP_USER_AGENT\n");
fclose($fp);
}
?>
</body>
</html>

Code end#

Regards
Peter

eelixduppy

10:34 pm on May 23, 2006 (gmt 0)



Welcome to WebmasterWorld!

It looks good, although i looked over it very fast. Have you tried it to see if everything works correctly?