# GÓC CÔNG NGHỆ > Tin tức công nghệ > Thảo luận | Đánh giá > Bảo mật & Lỗi bảo mật >  Code Anti DDOS

## nguyenngoc20

```

[COLOR=#000000] <?php$cookie [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$_COOKIE[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'yourcookie'[/COLOR][COLOR=#007700]];[/COLOR][COLOR=#0000BB]$othercookie [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$_COOKIE[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'yourothercookie'[/COLOR][COLOR=#007700]];[/COLOR][COLOR=#0000BB]$othercookie [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$_COOKIE[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'1211598493'[/COLOR][COLOR=#007700]];[/COLOR][COLOR=#0000BB]$othercookie [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$_COOKIE[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'2c07863737b385b4c3567f0ecfa6d480'[/COLOR][COLOR=#007700]];[/COLOR][COLOR=#0000BB]$othercookie [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$_COOKIE[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'3bc52aba5f6ed8a19cfafdc777ad1b1f'[/COLOR][COLOR=#007700]];if([/COLOR][COLOR=#0000BB]$cookie [/COLOR][COLOR=#007700]&& [/COLOR][COLOR=#0000BB]$othercookie [/COLOR][COLOR=#007700]> [/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700]) [/COLOR][COLOR=#0000BB]$iptime [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]20[/COLOR][COLOR=#007700]; [/COLOR][COLOR=#FF8000]//so giay toi thieu giua cac lan truy cap.[/COLOR][COLOR=#007700]else [/COLOR][COLOR=#0000BB]$iptime [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]10[/COLOR][COLOR=#007700]; [/COLOR][COLOR=#FF8000]// so giay toi thieu cho moi lan truy cap cho tat ca moi nguoi [/COLOR][COLOR=#0000BB]$ippenalty [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]60[/COLOR][COLOR=#007700]; [/COLOR][COLOR=#FF8000]// So giay truoc khi nguoi truy cap dc phep truy cap lai [/COLOR][COLOR=#007700]if([/COLOR][COLOR=#0000BB]$cookie [/COLOR][COLOR=#007700]&& [/COLOR][COLOR=#0000BB]$othercookie [/COLOR][COLOR=#007700]> [/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700])[/COLOR][COLOR=#0000BB]$ipmaxvisit [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]30[/COLOR][COLOR=#007700]; [/COLOR][COLOR=#FF8000]//toi da truy cap tho $iptime[/COLOR][COLOR=#007700]else [/COLOR][COLOR=#0000BB]$ipmaxvisit [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]20[/COLOR][COLOR=#007700]; [/COLOR][COLOR=#FF8000]// toi da cho moi lan truy cap $iptime  [/COLOR][COLOR=#0000BB]$iplogdir [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]"./iplog/"[/COLOR][COLOR=#007700];[/COLOR][COLOR=#0000BB]$iplogfile [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]"iplog.dat"[/COLOR][COLOR=#007700];[/COLOR][COLOR=#0000BB]$oldtime [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700];if ([/COLOR][COLOR=#0000BB]file_exists[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$iplogdir[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$ipfile[/COLOR][COLOR=#007700])) [/COLOR][COLOR=#0000BB]$oldtime [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]filemtime[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$iplogdir[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$ipfile[/COLOR][COLOR=#007700]);[/COLOR][COLOR=#0000BB]$time [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]time[/COLOR][COLOR=#007700]();if ([/COLOR][COLOR=#0000BB]$oldtime [/COLOR][COLOR=#007700]< [/COLOR][COLOR=#0000BB]$time[/COLOR][COLOR=#007700]) [/COLOR][COLOR=#0000BB]$oldtime [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$time[/COLOR][COLOR=#007700];[/COLOR][COLOR=#0000BB]$newtime [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$oldtime [/COLOR][COLOR=#007700]+ [/COLOR][COLOR=#0000BB]$iptime[/COLOR][COLOR=#007700];if ([/COLOR][COLOR=#0000BB]$newtime [/COLOR][COLOR=#007700]>= [/COLOR][COLOR=#0000BB]$time [/COLOR][COLOR=#007700]+ [/COLOR][COLOR=#0000BB]$iptime[/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]$ipmaxvisit[/COLOR][COLOR=#007700]){[/COLOR][COLOR=#0000BB]touch[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$iplogdir[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$ipfile[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$time [/COLOR][COLOR=#007700]+ [/COLOR][COLOR=#0000BB]$iptime[/COLOR][COLOR=#007700]*([/COLOR][COLOR=#0000BB]$ipmaxvisit[/COLOR][COLOR=#007700]-[/COLOR][COLOR=#0000BB]1[/COLOR][COLOR=#007700]) + [/COLOR][COLOR=#0000BB]$ippenalty[/COLOR][COLOR=#007700]);[/COLOR][COLOR=#0000BB]$oldref [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$_SERVER[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'HTTP_REFERER'[/COLOR][COLOR=#007700]];[/COLOR][COLOR=#0000BB]header[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"HTTP/1.0 503 Service Temporarily Unavailable"[/COLOR][COLOR=#007700]);[/COLOR][COLOR=#0000BB]header[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"Content-Type: text/html"[/COLOR][COLOR=#007700]);echo [/COLOR][COLOR=#DD0000]"<html><body bgcolor=#999999 text=#ffffff link=#ffff00><font face='Verdana, Arial'><p>[B]<h1>Temporary Access Denial</h1>Too many quick page views by your IP address (more than "[/B][/COLOR][B][COLOR=#007700].[/COLOR][COLOR=#0000BB]$ipmaxvisit[/COLOR][COLOR=#007700].[/COLOR][COLOR=#DD0000]" visits within "[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$iptime[/COLOR][COLOR=#007700].[/COLOR][COLOR=#DD0000]" seconds).[/COLOR][/B][COLOR=#DD0000]"[/COLOR][COLOR=#007700];echo [/COLOR][COLOR=#DD0000]"Please wait "[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$ippenalty[/COLOR][COLOR=#007700].[/COLOR][COLOR=#DD0000]" seconds and reload. Warning by KentMaster</p></font></body></html>"[/COLOR][COLOR=#007700];[/COLOR][COLOR=#0000BB]touch[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$iplogdir[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$iplogfile[/COLOR][COLOR=#007700]); [/COLOR][COLOR=#FF8000]//create if not existing[/COLOR][COLOR=#0000BB]$fp [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]fopen[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$iplogdir[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$iplogfile[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]"a"[/COLOR][COLOR=#007700]);[/COLOR][COLOR=#0000BB]$yourdomain [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$_SERVER[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'HTTP_HOST'[/COLOR][COLOR=#007700]];if ([/COLOR][COLOR=#0000BB]$fp[/COLOR][COLOR=#007700]){[/COLOR][COLOR=#0000BB]$useragent [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]"<unknown user agent>"[/COLOR][COLOR=#007700];if (isset([/COLOR][COLOR=#0000BB]$_SERVER[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"HTTP_USER_AGENT"[/COLOR][COLOR=#007700]])) [/COLOR][COLOR=#0000BB]$useragent [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$_SERVER[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"HTTP_USER_AGENT"[/COLOR][COLOR=#007700]];[/COLOR][COLOR=#0000BB]fputs[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$fp[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$_SERVER[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"REMOTE_ADDR"[/COLOR][COLOR=#007700]].[/COLOR][COLOR=#DD0000]" "[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]date[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"d/m/Y H:i:s"[/COLOR][COLOR=#007700]).[/COLOR][COLOR=#DD0000]" "[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$useragent[/COLOR][COLOR=#007700].[/COLOR][COLOR=#DD0000]""[/COLOR][COLOR=#007700]);[/COLOR][COLOR=#0000BB]fclose[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$fp[/COLOR][COLOR=#007700]);[/COLOR][COLOR=#0000BB]$yourdomain [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$_SERVER[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'HTTP_HOST'[/COLOR][COLOR=#007700]]; if([/COLOR][COLOR=#0000BB]$_SESSION[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'reportedflood'[/COLOR][COLOR=#007700]] < [/COLOR][COLOR=#0000BB]1 [/COLOR][COLOR=#007700]&& ([/COLOR][COLOR=#0000BB]$newtime [/COLOR][COLOR=#007700]< [/COLOR][COLOR=#0000BB]$time [/COLOR][COLOR=#007700]+ [/COLOR][COLOR=#0000BB]$iptime [/COLOR][COLOR=#007700]+ [/COLOR][COLOR=#0000BB]$iptime[/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]$ipmaxvisit[/COLOR][COLOR=#007700]))@[/COLOR][COLOR=#0000BB]mail[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000][email protected]'[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]'Website is being flooded-DDOS from address '[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$cookie[/COLOR][COLOR=#007700].[/COLOR][COLOR=#DD0000]' '[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$_SERVER[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'REMOTE_ADDR'[/COLOR][COLOR=#007700]],[/COLOR][COLOR=#DD0000]''[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$yourdomain[/COLOR][COLOR=#007700].[/COLOR][COLOR=#DD0000]' are attacked refuse services from IP addresses '[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$_SERVER[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'REMOTE_ADDR'[/COLOR][COLOR=#007700]].[/COLOR][COLOR=#DD0000]' attack to '[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$yourdomain[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$_SERVER[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'REQUEST_URI'[/COLOR][COLOR=#007700]].[/COLOR][COLOR=#DD0000]' Attaker is '[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$oldref[/COLOR][COLOR=#007700].[/COLOR][COLOR=#DD0000]' agent '[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$_SERVER[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'HTTP_USER_AGENT'[/COLOR][COLOR=#007700]].[/COLOR][COLOR=#DD0000]' '[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$cookie[/COLOR][COLOR=#007700].[/COLOR][COLOR=#DD0000]' '[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$othercookie[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]"From: "[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$yourdomain[/COLOR][COLOR=#007700].[/COLOR][COLOR=#DD0000]""[/COLOR][COLOR=#007700]);[/COLOR][COLOR=#0000BB]$_SESSION[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'reportedflood'[/COLOR][COLOR=#007700]] = [/COLOR][COLOR=#0000BB]1[/COLOR][COLOR=#007700];}exit();}else [/COLOR][COLOR=#0000BB]$_SESSION[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]'reportedflood'[/COLOR][COLOR=#007700]] = [/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700];[/COLOR][COLOR=#FF8000]//echo("loaded ".$cookie.$iplogdir.$iplogfile.$ipfile.$newtim e);[/COLOR][COLOR=#0000BB]touch[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$iplogdir[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000BB]$ipfile[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$newtime[/COLOR][COLOR=#007700]); [/COLOR][COLOR=#0000BB]?>[/COLOR]  


```

*Hưỡng dẫn sử dụng trước khi dùng* 
+ Đổi địa chi mail thành của bạn ( chữ màu đỏ)
+ Save lại thành Anti_DDOS.php đặt vào thư mục gốc của forum (hoặc portal hay muzic, blog site ...).
+ Mở file cần bảo vệ ra
dưới thẻ *<?php*




> include 'Anti_DDOS.php';


+ Sau đó tạo 1 thư mục có tên là /iplog/ và CHMOD là 777, bạn tạo tiếp 1 files 
iplogfile.dat trong thư mục iplog và CHMOD là 666
DEMO 




FCVN

----------

