<?php
$ipLog='ipLogFile.txt'; // Your logfiles name here
$timeout='24'; // How many hours to block IP
$goHere='Allowed.html'; // Allowed pages name here
// PHP script by Dave Lauderdale
// Published at: www.digi-dl.com
function recordData($REMOTE_ADDR,$ipLog,$goHere)
{
$log=fopen("$ipLog", "a+");
fputs ($log,$REMOTE_ADDR."][".time()."\n");
fclose($log);
Header ("Location: $goHere"); exit(0);
}
function checkLog($REMOTE_ADDR,$ipLog,$timeout)
{
global $valid; $ip=$REMOTE_ADDR;
$data=file("$ipLog"); $now=time();
foreach ($data as $record)
{
$subdata=explode("][",$record);
if ($now < ($subdata[1]+3600*$timeout) && $ip == $subdata[0])
{
$valid=0; echo "You have been banned from accessing this page. Try again in $timeout hours.";
break;
}
}
}
checkLog($REMOTE_ADDR,$ipLog,$timeout);
if ($valid!="0") recordData($REMOTE_ADDR,$ipLog,$goHere);
?>