For my bad robots trap, I have this controlling code. When the number of IP addresses reaches
above 250, it's meant to remove the first 50 lines, leaving the latest 200 bad fellahs behind.
The file then hovers at around 3Kb in size. Now, I have a blacklist.dat that's 0 bytes, but I
don't know where to begin to solve this...
The server is running PHP 5.2.13
Code: Select all
<?php
error_reporting(E_ALL ^ E_NOTICE);
extract($_SERVER);
$badbot = 0;
$filename = ($_SERVER["DOCUMENT_ROOT"] . "/blacklist.dat");
$fp = fopen($filename, "r") or die ("Error opening file ...");
while ($line = fgets($fp,255)) {
$u = explode(" ",$line);
if (ereg($u[0],$REMOTE_ADDR)) {$badbot++;}
}
fclose($fp);
if ($badbot == 0) {
$fp = fopen($filename,'a+');
fwrite($fp,"$REMOTE_ADDR \n");
fclose($fp);
$filearray=file($filename);
$fp = fopen($filename,"w");
$c=count($filearray);
if ($c >= 250) {
for($i=($c < 200 ? 0 : $c-200);$i < $c;++$i) {
fputs($fp,$filearray[$i]);
}
fwrite($fp,"\t\t\t\t\t\t\t\t\t\ $datum \n");
}
fclose($fp);
}
echo '<html>
<head>
<title>X Mail For Badly-Behaved Bots</title>
</head>
<body>
<p>If there is nothing to see, what are you doing here ?</p>
<p><a href="http://caronia2.info/">Go home.</a></p>
</body>
</html>';
?>