当前位置:Gxlcms > PHP教程 > phpcc攻击防御与防快速刷新代码

phpcc攻击防御与防快速刷新代码

时间:2021-07-01 10:21:17 帮助过:15人阅读

  1. //代理IP直接退出
  2. empty($_SERVER['HTTP_VIA']) or exit('Access Denied');
  3. //防止快速刷新
  4. session_start();
  5. $seconds = '3'; //时间段[秒]
  6. $refresh = '5'; //刷新次数
  7. //设置监控变量
  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. //处理监控结果
  16. if($cur_time - $_SESSION['last_time'] < $seconds){
  17. if($_SESSION['refresh_times'] >= $refresh){
  18. //跳转至攻击者服务器地址
  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. ?>

人气教程排行