Free IP blocker with time limit - timed IP blocker JavaScript

This is just a simple IP blocker script that will log the IP address of anyone who accesses the page and the time the page was accessed and wont let them come back for a set time limit. You can set the time limit to whatever you want. This script will require that the log file have writable permissions.




<?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);

?>