PHP prohibits frequent access to the same IP to prevent the site from being protected against attack or collection of code
<?php
/*
* Prevent the website from being protected against attack code by prohibiting frequent IP access
*design by www.scutephp.com
*/
Header (' content-type:text/html; Charset=utf-8 ');
$ip =$_server[' remote_addr '];//get the IP of the current visitor
$logFilePath = './log/';//log record file save directory
$fileht = '. Htaccess2 ';//Forbidden IP record file
$allowtime =60;//anti-refresh Time
$allownum =5;//anti-refresh times
$allowRefresh =120;//added to the Forbidden IP file after the number of refresh times allowed
if (!file_exists ($fileht)) {
File_put_contents ($fileht, ");
}
[Email protected] ($FILEHT);
if (In_array ($ip. " \ r \ n ", $filehtarr)) {
Exit (' Warning: Your IP has been banned! ‘);
}
Add Forbidden IP
$time =time ();
$fileforbid = $logFilePath. ' Forbidchk.dat ';
if (file_exists ($fileforbid)) {
if ($time-filemtime ($fileforbid) >30) {
@unlink ($fileforbid);
}else{
[Email protected] ($fileforbid);
if ($ip ==substr ($fileforbidarr [0],0,strlen ($IP))) {
if ($time-substr ($fileforbidarr [1],0,strlen ($time)) >120) {
@unlink ($fileforbid);
}else if ($fileforbidarr [2]> $allowRefresh) {
File_put_contents ($fileht, $ip. " \ r \ n ", file_append);
@unlink ($fileforbid);
}else{
$fileforbidarr [2]++;
File_put_contents ($fileforbid, $fileforbidarr);
}
}
}
}
Anti-Refresh
$str = ";
$file = $logFilePath. ' Ipdate.dat ';
if (!file_exists ($logFilePath) &&!is_dir ($logFilePath)) {
mkdir ($logFilePath, 0777);
}
if (!file_exists ($file)) {
File_put_contents ($file, ");
}
$uri =$_server[' Request_uri '];//get the address of the page file currently visited
$checkip =md5 ($IP);
$checkuri =md5 ($uri);
$yesno =true;
[Email protected] ($file);
foreach ($ipdate as $k = = $v) {
$iptem =substr ($v, 0,32);
$uritem =substr ($v, 32,32);
$timetem =substr ($v, 64,10);
$numtem =substr ($v, 74);
if ($time-$timetem < $allowtime) {
if ($iptem! = $checkip) {
$str. = $v;
}else{
$yesno =false;
if ($uritem! = $checkuri) {
$str. = $iptem. $checkuri. $time. " \ r \ n ";
}else if ($numtem < $allownum) {
$str. = $iptem. $uritem. $timetem. ($numtem + 1). " \ r \ n ";
}
else{
if (!file_exists ($fileforbid)) {
$addforbidarr =array ($ip. " \ r \ n ", Time ()." \ r \ n ", 1);
File_put_contents ($fileforbid, $addforbidarr);
}
File_put_contents ($logFilePath. ' Forbided_ip.log ', $ip. ' --'. Date (' y-m-d h:i:s ', Time ()). ' --'. $uri. ' \ r \ n ", file_append);
$timepass = $timetem + $allowtime-$time;
Exit (' Warning: Do not refresh too often! ‘);
}
}
}
}
if ($yesno) {
$str. = $checkip. $checkuri. $time. " \ r \ n ";
}
File_put_contents ($file, $STR);
PHP prohibits frequent access to the same IP to prevent the site from being protected against attack or collection of code