Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////// ЗАЩИТА ОТ DDOS АТАК ///////////////////
- // $link -- соединение с БД, $ip_text -- IP-адрес
- define('ALERT_TIME',300);
- define('ALERT_COUNT',150);
- function check_dos($ip_text, $link) {
- $ip=ip2long($ip_text);
- $res=mysql_query($link,'SELECT lasttime, count, status FROM ip_check WHERE ip="'.$ip.'"');
- if (mysql_num_rows($res)==0) { // нет такого IP
- $count=1;
- mysql_query($link,'INSERT INTO ip_check (lasttime,count,ip,status) VALUES ('.time().',1,"'.$ip.'",0)');
- }
- else {
- $data=mysql_fetch_row($res);
- $status=$data[2];
- if ($status!=2 && ($data[0]<time()-ALERT_TIME || $data[1]<ALERT_COUNT))) $count=1;
- elseif ($status!=2) { $count=$data[1]+1; if ($count>=ALERT_COUNT) $status=1; }
- if ($status!=2) {
- mysql_query($link,'UPDATE ip_check SET count='.$count,', status='.$status.', lasttime='.time().' WHERE ip="'.$ip.'"';
- }
- if ($status) {
- header($_SERVER['HTTP_PROTOCOL'].' 503 Temporary Unavailable');
- trigger_error('Превышено число допустимых запросов!',E_USER_ERROR);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment