zoukankan      html  css  js  c++  java
  • 限制IP频繁访问

     
     用session防止IP频繁访问的方法

     

    //代理IP直接退出
    empty($_SERVER['HTTP_VIA']) or exit('Access Denied');
    //防止快速刷新
    session_start();
    $seconds = '3'; //时间段[秒]
    $refresh = '5'; //刷新次数
    //设置监控变量
    $cur_time = time();
    if(isset($_SESSION['last_time'])){
        $_SESSION['refresh_times'] += 1;
    }else{
        $_SESSION['refresh_times'] = 1;
        $_SESSION['last_time'] = $cur_time;
    }
    //处理监控结果
    if($cur_time - $_SESSION['last_time'] < $seconds){
        if($_SESSION['refresh_times'] >= $refresh){
            //跳转至攻击者服务器地址
            header(sprintf('Location:%s', 'http://www.baidu.com'));
            exit('Access Denied');
        }
    }else{
        $_SESSION['refresh_times'] = 0;
        $_SESSION['last_time'] = $cur_time;
    }

    参考网址:

    https://www.chingli.net/779.html

     

  • 相关阅读:
    图书排列
    L1-059 敲笨钟 (20 分)
    区间移位
    取球博弈
    poj 2456 Aggressive cows
    对局匹配
    发现环
    数字划分
    哥德巴赫分解
    把数组排成最小的数
  • 原文地址:https://www.cnblogs.com/sien6/p/13899811.html
Copyright © 2011-2022 走看看