防刷功能的实现(thinkphp5)

$seconds = '3'; //时间段[秒]
$refresh = '3';//最大次数
$cur_time = time();
if(Session::get('refresh_times')){
    Session::set('refresh_times',Session::get('refresh_times')+1);
}else{
    Session::set('refresh_times',1);
    Session::set('last_time',$cur_time);
}
if($cur_time - Session::get('last_time') < $seconds){
    if(Session::get('refresh_times') >= $refresh){
      //处理工作
    }
}else{
    Session::set('refresh_times',0);
    Session::set('last_time',$cur_time);
}

猜你喜欢

转载自www.cnblogs.com/dongqiliang/p/12938858.html