All pastes #581330 Raw Edit

BotBlocker Engine

public php v1 · immutable
·published 2007-06-21 13:59 UTC
rendered paste body
<?php$botbanner_itime = 5; // Minimum number of seconds between visits$botblocker_itime = 10; // Minimum number of seconds between visits$botblocker_ipenalty = 60; // Seconds before visitor is allowed back$botblocker_imaxvisit = 45; // Maximum visits$botblocker_iplogdir = $_SERVER["DOCUMENT_ROOT"]."/botblocker/";$botblocker_iplogfile = "iplog.dat";$botblocker_ipfile = substr(md5($_SERVER["REMOTE_ADDR"]), -2);$botblocker_oldtime = 0;if (file_exists($botblocker_iplogdir.$botblocker_ipfile)) $botblocker_oldtime = filemtime($botblocker_iplogdir.$botblocker_ipfile);$botblocker_time = time();if ($botblocker_oldtime < $botblocker_time) $botblocker_oldtime = $botblocker_time;$botblocker_newtime = $botblocker_oldtime + $botblocker_itime;if ($botblocker_newtime >= $botblocker_time + $botblocker_itime*$botblocker_imaxvisit){touch($botblocker_iplogdir.$botblocker_ipfile, $botblocker_time + $botblocker_itime*($botblocker_imaxvisit-1) + $botblocker_ipenalty);header("HTTP/1.0 503 Service Temporarily Unavailable");header("Connection: close");header("Content-Type: text/html");echo "<html><body><p><b>Server under heavy load</b><br>";echo "Please wait $botblocker_ipenalty seconds and try again</p></body></html>";$botblocker_fp = fopen($botblocker_iplogdir.$botblocker_iplogfile, "a");if ($botblocker_fp){$botblocker_useragent = "<unknown user agent>";if (isset($_SERVER["HTTP_USER_AGENT"])) $botblocker_useragent = $_SERVER["HTTP_USER_AGENT"];fputs($botblocker_fp, $_SERVER["REMOTE_ADDR"]." ".date("d/m/Y H:i:s")." ".$botblocker_useragent."\n");fclose($botblocker_fp);}exit();}touch($botblocker_iplogdir.$botblocker_ipfile, $botblocker_newtime);?>