Home  >  Article  >  Backend Development  >  Yii uses sessions in the middle and backend to prevent repeated submissions and flooding

Yii uses sessions in the middle and backend to prevent repeated submissions and flooding

伊谢尔伦
伊谢尔伦Original
2016-11-26 13:59:551068browse

1. From the front-end perspective: add mask

2. From the back-end perspective: use session

$session = Yii::app()->session;
$user_id = Yii::app()->user->id;
$sessionKey = $user_id.'_is_sending';
if(isset($session[$sessionKey])){
    $first_submit_time = $session[$sessionKey];
    $current_time = time();
    if($current_time - $first_submit_time < 10){
        $session[$sessionKey] = $current_time;
        $this->response(array(&#39;status&#39;=>1, &#39;msg&#39;=>&#39;不能在10秒钟内连续发送两次。&#39;));
    }else{
        unset($session[$sessionKey]);//超过限制时间,释放session";
    }
}
//第一次点击确认按钮时执行
if(!isset($session[$sessionKey])){
    $session[$sessionKey] = time();
}


Statement:
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