Home  >  Article  >  Backend Development  >  PHP cc attack defense and fast refresh code

PHP cc attack defense and fast refresh code

WBOY
WBOYOriginal
2016-07-25 08:54:241080browse
  1. //Exit the proxy IP directly
  2. empty($_SERVER['HTTP_VIA']) or exit('Access Denied');
  3. //Prevent quick refresh
  4. session_start();
  5. $seconds = '3'; //Time period [seconds]
  6. $refresh = '5'; //Number of refreshes
  7. //Set monitoring variables
  8. $cur_time = time();
  9. if(isset($_SESSION['last_time'] )){
  10. $_SESSION['refresh_times'] += 1;
  11. }else{
  12. $_SESSION['refresh_times'] = 1;
  13. $_SESSION['last_time'] = $cur_time;
  14. }
  15. //Process monitoring results
  16. if($cur_time - $_SESSION['last_time'] < $seconds){
  17. if($_SESSION['refresh_times'] >= $refresh){
  18. //Jump to attacker server address
  19. header(sprintf ('Location:%s', 'http://127.0.0.1'));
  20. exit('Access Denied');
  21. }
  22. }else{
  23. $_SESSION['refresh_times'] = 0;
  24. $_SESSION[ 'last_time'] = $cur_time;
  25. }
  26. ?>
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn