Home > php教程 > php手册 > 用于过滤快速重复的请求

用于过滤快速重复的请求

WBOY
Release: 2016-06-06 19:35:53
Original
960 people have browsed it

无详细内容 无 ?phpfunction C($key){ $c_arr = array( 'DDOS_MEMCACHE_PERSISTENT_ID_COUNT' = 200, 'DDOS_MEMCACHE_HOST' = '127.0.0.1', // 需要重启apache生效 'DDOS_MEMCACHE_PORT' = 11211, // 需要重启apache生效 'DDOS_MEMCACHE_EXPIRE' = 2, ); retu

<?php
function C($key){
    $c_arr = array(
        'DDOS_MEMCACHE_PERSISTENT_ID_COUNT' => 200,
        'DDOS_MEMCACHE_HOST' => '127.0.0.1',    // 需要重启apache生效
        'DDOS_MEMCACHE_PORT' =>  11211,         // 需要重启apache生效
        'DDOS_MEMCACHE_EXPIRE' => 2,
    );
    return $c_arr[$key];
}


/**
 * @brief isDdos 判断是否为过快速的ddos攻击
 *
 * @param $index_arr
 *
 * @return 
 */
function isDdos($index_arr){
    $persistent_id = mt_rand(1, C('DDOS_MEMCACHE_PERSISTENT_ID_COUNT'));
    $m = new Memcached($persistent_id);
    if(!$m->getServerList()) { 
        $m->addServer(C('DDOS_MEMCACHE_HOST'), C('DDOS_MEMCACHE_PORT'));
    } 
    $key = md5(http_build_query($index_arr));
    $ret = $m->get($key) === 1 ? true : false;
    $m->set($key, 1, C('DDOS_MEMCACHE_EXPIRE'));
    return $ret;
}

if(isDdos(array('tjx', 'fdf'))){
    echo 'ddos';
    die();
}

sleep(2);
echo 'return value';
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template