防刷功能的实现(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);
}

 

posted @ 2020-05-22 18:15  不懂相处  阅读(611)  评论(0编辑  收藏  举报