Php methods for implementing cc AttacK Defense and examples of preventing Quick Page refreshing
This article mainly introduces how php implements cc AttacK Defense and How to Prevent Quick Page refreshing. For more information, see
The Code is as follows:
<? Php
// 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;
}
?>