Recently the site is often attacked, and later thought of a use of PHP to prevent the site from attack, the following is my code, the code is not the best, according to their own needs to do, the following to see my code.
Recently the site is often attacked, and later thought of a PHP tutorial to prevent the site from attack, the following is my code, the code is not the best, according to their own needs to do, the following to see my code.
/*
* Web site Anti-IP attack code (ANTI-IP attack code website) 2010-11-20,ver2.0
*mydalle.com Anti-refresh mechanism
*design by www.bKjia.c0m
*/
Query prohibit IP
$ip =$_server[' remote_addr '];
$fileht = ". Htaccess2";
if (!file_exists ($fileht)) file_put_contents ($fileht, "");
$filehtarr = @file ($fileht);
if (In_array ($ip. " RN ", $filehtarr)" Die ("Warning:". ")
"." Your IP address is forbided by mydalle.com Anti-refresh mechanism and if you had any question pls emill to shop@mydalle.com !
(mydalle.com Anti-refresh mechanism is to enable the users to has a good shipping services, but there maybe some inevitable n etwork problems in your IP address, so (can mail to us to solve.));
Add Forbidden IP
$time =time ();
$fileforbid = "Log/forbidchk.dat";
if (file_exists ($fileforbid))
{if ($time-filemtime ($fileforbid) >30) unlink ($fileforbid);
else{
$fileforbidarr = @file ($fileforbid);
if ($ip ==substr ($fileforbidarr [0],0,strlen ($IP)))
{
if ($time-substr ($fileforbidarr [1],0,strlen ($time)) >120) unlink ($fileforbid);
ElseIf ($fileforbidarr [2]>120) {file_put_contents ($fileht, $ip. " RN ", file_append); unlink ($fileforbid);}
else{$fileforbidarr [2]++;file_put_contents ($fileforbid, $fileforbidarr);}
}
}
}
Anti-Refresh
$str = "";
$file = "Log/ipdate.dat";
if (!file_exists ("Log") &&!is_dir ("Log")) mkdir ("Log", 0777);
if (!file_exists ($file)) file_put_contents ($file, "");
$allowtime = 60;//anti-refresh Time
$allownum =5;//anti-refresh times
$uri =$_server[' Request_uri '];
$checkip =md5 ($IP);
$checkuri =md5 ($uri);
$yesno =true;
$ipdate = @file ($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. " 1rn ";
ElseIf ($numtem < $allownum) $str. = $iptem. $uritem. $timetem. ($numtem + 1). " RN ";
Else
{
if (!file_exists ($fileforbid)) {$addforbidarr =array ($ip. ") RN ", Time ()." RN ", 1); File_put_contents ($fileforbid, $addforbidarr);}
File_put_contents ("Log/forbided_ip.log", $ip. " --". Date (" Y-m-d h:i:s ", Time ())." --". $uri." RN ", file_append);
$timepass = $timetem + $allowtime-$time;
Die ("Warning:". ")
"." pls don ' t refresh too frequently, and wait for ". $timepass." Seconds to continue, if not your IP address would be forbided Automatic by mydalle.com Anti-refresh mechanism!
(mydalle.com Anti-refresh mechanism is to enable the users to has a good shipping services, but there maybe some inevitable n etwork problems in your IP address, so (can mail to us to solve.));
}
}
}
}
if ($yesno) $str. = $checkip. $checkuri. $time. " 1rn ";
File_put_contents ($file, $STR);
?>
http://www.bkjia.com/PHPjc/629736.html www.bkjia.com true http://www.bkjia.com/PHPjc/629736.html techarticle recently the site is often attacked, and later thought of a use of PHP to prevent the site from attack, the following is my code, the code is not the best, according to their own needs to do, the following ...