PHP防Cc攻击

2018-06-11  本文已影响0人  会写bug的鸟

//代理 IP 直接退出 

empty($_SERVER['HTTP_VIA']) or exit('Access Denied');

//防止快速刷新 

session_start(); 

$min_seconds = 1; //段[秒]

$max_refresh_times = 8; //刷新次数

session_start();

$_SESSION = array();

//print_r($_SESSION);die;

if(isset($_SESSION['refresh_times']) && isset($_SESSION['last_time'])){

    if($_SESSION['refresh_times'] >= $max_refresh_times){

        die;

    }

    if(time() - $_SESSION['last_time'] <= $min_seconds){//不排除刷接口嫌疑

        $_SESSION['refresh_times'] += 1;

    }else{

        $_SESSION['refresh_times'] = 1;

        $_SESSION['last_time'] = time();

    }

}else{

    $_SESSION['refresh_times'] = 1;

    $_SESSION['last_time'] = time();

}

上一篇下一篇

猜你喜欢

热点阅读