
21.11.2007, 08:33
|
|
Постоянный
Регистрация: 15.03.2006
Сообщений: 600
Провел на форуме: 5091304
Репутация:
1203
|
|
PHP код:
<?php
$ipLog='ipLogFile.txt'; // Your logfiles name here
$timeout='24'; // How many hours to block IP
$goHere='Allowed.html'; // Allowed pages name here
function record($REMOTE_ADDR,$ipLog,$goHere)
{
$log=fopen("$ipLog", "a+");
fputs ($log,$REMOTE_ADDR."][".time()."\n");
fclose($log);
Header ("Location: $goHere"); exit(0);
}
function check($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;
}
}
}
check($REMOTE_ADDR,$ipLog,$timeout);
if ($valid!="0") record($REMOTE_ADDR,$ipLog,$goHere);
?>
|
|
|