美文网首页
PHP防Cc攻击

PHP防Cc攻击

作者: 会写bug的鸟 | 来源:发表于2018-06-11 21:27 被阅读0次

//代理 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();

}

相关文章

网友评论

      本文标题:PHP防Cc攻击

      本文链接:https://www.haomeiwen.com/subject/tghkeftx.html