
This module is designed to limit access to the site or to pages where it is on.
Principle of operation that is stored ip-address and time of treatment with this address. And if within the specified time is the treatment of the same address, then he / she receives an error 503. Ex : If you click the Refresh button 3 times will give you will give this message.
Installation:
* In the site root folder, create a tmp directory and CHMOD to 777
* Open index.php and before:
<?php
Insert:
<?php
$ad_delay=2;
$ad_DirName=$_SERVER['DOCUMENT_ROOT'].'/tmp';
$ad_Robots_UserAgent=array(
'aipbot',
'Aport',
'eStyleSearch',
'Gigabot',
'Gokubot',
'Google',
'MJ12bot',
'msnbot',
'PlantyNet_WebRobot',
'StackRambler',
'TurtleScanner',
'Yahoo',
'Yandex',
'YaDirectBot',
);
$ad_good_ip = array(
'217.107.36.73',
);
function ad_WiteIP($dir){
$f=fopen($dir.'/a'.$_SERVER['REMOTE_ADDR'], 'w');
fclose($f);
}
$ad_IsRobot=false;
foreach ($ad_Robots_UserAgent as $match){
if (strstr($_SERVER['HTTP_USER_AGENT'], $match)){
$ad_IsRobot=true;
break;
}
}
if( in_array($_SERVER['REMOTE_ADDR'], $ad_good_ip) ) {
$good_ip = true;
} else {
$good_ip = false;
}
if (!$ad_IsRobot AND !$good_ip){
session_start();
}
if (!$ad_IsRobot AND !$good_ip){
$ad_dir =opendir($ad_DirName)
or die('There is no directory for temporary files');
$ad_now =time();
$ad_forbid =$ad_now-$ad_delay;
while (false!==($ad_FName=readdir($ad_dir))){
if (ereg('^a[1-9]',$ad_FName)
&& (@ filemtime($ad_DirName.'/'.$ad_FName)<$ad_forbid)){
@ unlink($ad_DirName.'/'.$ad_FName);
}
}
closedir($ad_dir);
if (file_exists($ad_DirName.'/a'.$_SERVER['REMOTE_ADDR'])){
header('HTTP/1.0 503 Service Unavailable');
header('Status: 503 Service Unavailable');
header('Retry-After: '.$ad_delay*3);
?>
<!doctype html public "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Ошибка 503</title>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1251" />
</head>
<body>
<h1>Error 503 (Service Unavailable)</h1>
<p>server can not currently issue the page you requested.
Try to access this page later (press F5).</p>
</body>
</html>
<?php
ad_WiteIP($ad_DirName); // Before exiting record ip
exit;
}else{
ad_WiteIP($ad_DirName);
}
}
?>
$ad_delay=2;
$ad_DirName=$_SERVER['DOCUMENT_ROOT'].'/tmp';
$ad_Robots_UserAgent=array(
'aipbot',
'Aport',
'eStyleSearch',
'Gigabot',
'Gokubot',
'Google',
'MJ12bot',
'msnbot',
'PlantyNet_WebRobot',
'StackRambler',
'TurtleScanner',
'Yahoo',
'Yandex',
'YaDirectBot',
);
$ad_good_ip = array(
'217.107.36.73',
);
function ad_WiteIP($dir){
$f=fopen($dir.'/a'.$_SERVER['REMOTE_ADDR'], 'w');
fclose($f);
}
$ad_IsRobot=false;
foreach ($ad_Robots_UserAgent as $match){
if (strstr($_SERVER['HTTP_USER_AGENT'], $match)){
$ad_IsRobot=true;
break;
}
}
if( in_array($_SERVER['REMOTE_ADDR'], $ad_good_ip) ) {
$good_ip = true;
} else {
$good_ip = false;
}
if (!$ad_IsRobot AND !$good_ip){
session_start();
}
if (!$ad_IsRobot AND !$good_ip){
$ad_dir =opendir($ad_DirName)
or die('There is no directory for temporary files');
$ad_now =time();
$ad_forbid =$ad_now-$ad_delay;
while (false!==($ad_FName=readdir($ad_dir))){
if (ereg('^a[1-9]',$ad_FName)
&& (@ filemtime($ad_DirName.'/'.$ad_FName)<$ad_forbid)){
@ unlink($ad_DirName.'/'.$ad_FName);
}
}
closedir($ad_dir);
if (file_exists($ad_DirName.'/a'.$_SERVER['REMOTE_ADDR'])){
header('HTTP/1.0 503 Service Unavailable');
header('Status: 503 Service Unavailable');
header('Retry-After: '.$ad_delay*3);
?>
<!doctype html public "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Ошибка 503</title>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1251" />
</head>
<body>
<h1>Error 503 (Service Unavailable)</h1>
<p>server can not currently issue the page you requested.
Try to access this page later (press F5).</p>
</body>
</html>
<?php
ad_WiteIP($ad_DirName); // Before exiting record ip
exit;
}else{
ad_WiteIP($ad_DirName);
}
}
?>

Updates
TV Online


