PHP anti-CC attack prevent quick code refresh

Source: Internet
Author: User

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.

<? Php/*** @ author Tianya * mail@phpha.com * // The proxy IP directly exits empty ($ _ SERVER ['HTTP _ VIA ']) or exit ('Access Denied '); // prevent fast refresh of session_start (); $ seconds = '3'; // time period [seconds] $ refresh = '5 '; // refresh times // set the monitoring variable $ cur_time = time (); if (isset ($ _ SESSION ['last _ time']) {$ _ SESSION ['refresh_times '] + = 1;} else {$ _ SESSION ['refresh_times'] = 1; $ _ SESSION ['last _ time'] = $ cur_time;} // process the monitoring result if ($ cur_time-$ _ SESSION ['last _ time'] <$ seconds) {if ($ _ SESSION ['refresh_times ']> = $ refresh) {// jump to the attacker server address header (sprintf ('location: % s', 'HTTP: // 127.0.0.1 '); exit ('Access Denied') ;}} else {$ _ SESSION ['refresh _ times '] = 0; $ _ SESSION ['last _ time'] = $ cur_time;}?>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.