A friend server is under attack. Currently, it can be determined that it is a CC attack. Therefore, a PHP anti-CC attack code is provided. This is a bit too much. In fact, it is to prevent the quick refresh of the generation.
A friend server is under attack. Currently, it can be determined that it is a CC attack. Therefore, a PHP anti-CC attack code is provided. This is a bit too much. In fact, it is to prevent the code from being refreshed quickly. This does not play a major role for so many fake IP addresses. CC attacks are really a headache. Directly add the code.
- /**
- * @ Author Tianya
- * Mail@phpha.com
- */
- // Directly exit the proxy IP address
- Empty ($ _ SERVER ['http _ vean']) or exit ('Access Denied ');
- // Prevents quick refresh
- Session_start ();
- $ Seconds = '3'; // time period [seconds]
- $ Refresh = '5'; // Number of Refreshes
- // Set monitoring variables
- $ Cur_time = time ();
- If (isset ($ _ SESSION ['last _ time']) {
- $ _ SESSION ['refresh_times '] + = 1;
- } Else {
- $ _ SESSION ['refresh_times '] = 1;
- $ _ SESSION ['last _ time'] = $ cur_time;
- }
- // Process monitoring results
- If ($ cur_time-$ _ SESSION ['last _ time'] <$ seconds ){
- If ($ _ SESSION ['refresh_times ']> = $ refresh ){
- // Jump to the attacker's server address
- Header (sprintf ('Location: % s', 'http: // 127.0.0.1 '));
- Exit ('Access Denied ');
- }
- } Else {
- $ _ SESSION ['refresh_times '] = 0;
- $ _ SESSION ['last _ time'] = $ cur_time;
- }
- ?>