Especially for users who use virtual hosts, if the CPU is overloaded, a "service unariable" prompt will appear. There are many factors related to overloading, such as unreasonable webpage structure and excessive traffic. Another possible malicious factor is CC attacks.
The so-called CC attack means that the other party uses programs or some agents to continuously access your website, resulting in your website being unable to handle and being in the status of a computer. In this case, your statistical system (which may be quantum or Baidu) cannot be used. However, we can use some anti-attack software, but the effect is sometimes not obvious. Next I will provide a piece of PHP code to prevent CC attacks.
Main function: in 3 seconds, the page will be refreshed more than 5 times in a row will point to the local http://www.bkjia.com
The Code is as follows:
$ P_S_T = $ t_array [0] + $ t_array [1];
$ Timestamp = time ();
Session_start ();
$ Ll_nowtime = $ timestamp;
If (session_is_registered (ll_lasttime )){
$ Ll_lasttime = $ _ SESSION [ll_lasttime];
$ Ll_times = $ _ SESSION [ll_times] + 1;
$ _ SESSION [ll_times] = $ ll_times;
} Else {
$ Ll_lasttime = $ ll_nowtime;
$ Ll_times = 1;
$ _ SESSION [ll_times] = $ ll_times;
$ _ SESSION [ll_lasttime] = $ ll_lasttime;
}
If ($ ll_nowtime-$ ll_lasttime) <3 ){
If ($ ll_times> = 5 ){
Header (sprintf ("Location: % s", http://www.bkjia.com ));
Exit;
}
} Else {
$ Ll_times = 0;
$ _ SESSION [ll_lasttime] = $ ll_nowtime;
$ _ SESSION [ll_times] = $ ll_times;
}
3 indicates the time interval, and 5 indicates the number of refreshes.
The above code can be stored in the inclusion file of each PHP file, so that each page can be protected against CC attacks. You can also set the parameters according to your own situation.