• discuz3.0以下版本防采集设置


    /**
     * 防采集设置
     * @global type $_G
     * @return boolean
     */
    function antitheft_control() {
        global $_G;
        //是否允许使用memcache
        $allowmem = memory('check');
        if(empty($allowmem)) {
            return true;
        }
        
        $lifetime = 86400; // memcache的生命周期
        $pervisittimes = 100; // 在单位时间内最多访问多少次
        $limitimes = 86400; //访问超过次数限制,限制多久不可以访问,前提是:memcache没有失效,所以memcache的生命周期不要太小于限制访问时间
        $intervaltime = 60; //单位时间;单位时间内访问次数超过限制次数,则禁止访问一段时间
        $antitheft = array(
            'white' => array(
                'single' => array('2130706433'),
                'range' => array(
                    array(
                        'min' => '',
                        'max' => ''
                    ),
                ),
            ),
            'black' => array(
                'single' => array(),
                'range' => array(
                    array(
                        'min' => '',
                        'max' => ''
                    ),
                ),
            ),
        );
        $ip = ip2long($_G['clientip']);
        if (!$ip || $ip == -1)
            showmessage('invalid request');
        if ($ip < 0) {
            $ip = sprintf('%u', $ip);
        }
        //此列出来的ip不受限制
        if (isset($antitheft['white'])) {
            if (in_array($ip, $antitheft['white']['single'])) {
                return true;
            }
            foreach ($antitheft['white']['range'] as $_ip) {
                if ($ip > $_ip['min'] && $ip < $_ip['max'])
                    return true;
            }
        }
        //此ip不可以访问
        if (isset($antitheft['black'])) {
            if (in_array($ip, (array) $antitheft['black']['single'], true)) {
                showmessage('have no right to visit again');
            }
            foreach ($antitheft['black']['range'] as $_ip) {
                if ($ip > $_ip['min'] && $ip < $_ip['max']) {
                    showmessage('have no right to visit again');
                }
            }
        }
        
        if (!($numarr = memory('get', $ip, 'iplimit'))) {
            $tmpval = json_encode(array(1, TIMESTAMP));
            memory('set', $ip, $tmpval, $lifetime, 'iplimit');
        } else {
            $numarr = json_decode($numarr, true);
            if (TIMESTAMP - $numarr[1] > $lifetime) {// 是否超过memcache的生命周期,如果是,从1开始计数
                $tmpval = json_encode(array(1, TIMESTAMP));
                memory('set', $ip, $tmpval, $lifetime, 'iplimit');
            } elseif ((TIMESTAMP - $numarr[1] > $intervaltime) && $numarr[0] > $pervisittimes) {//单位时间内超过了访问次数
                $tmpval = json_encode(array($pervisittimes + 1, $numarr[1]));
                memory('set', $ip, $tmpval, $limitimes, 'iplimit');
                showmessage('have no right to visit again');
            } else {//计数,更新memcache
                $tmpval = json_encode(array($numarr[0] + 1, $numarr[1]));
                memory('set', $ip, $tmpval, $lifetime, 'iplimit');
            }
        }
    }
  • 相关阅读:
    vue 组件开发 props 验证
    vue中$emit与$on
    vue中的 ref 和 $refs
    Animate.css动画特效
    Css Tada动画效果(Css Tada Animation Effect)--- shake抖动效果
    给某个dom对象添加动画fadeIn、fadeInDown、flipInY、jackInTheBox
    uniapp导航栏自定义按钮及点击事件
    uniapp的微信小程序,获取授权,获取中文街道地理位置
    在mac上如何用safari调试ios手机的移动端页面
    条件编译
  • 原文地址:https://www.cnblogs.com/bandbandme/p/3089195.html
Copyright © 2020-2023  润新知