Home > Article > Backend Development > Yii uses sessions in the middle and backend to prevent repeated submissions and flooding
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('status'=>1, 'msg'=>'不能在10秒钟内连续发送两次。')); }else{ unset($session[$sessionKey]);//超过限制时间,释放session"; } } //第一次点击确认按钮时执行 if(!isset($session[$sessionKey])){ $session[$sessionKey] = time(); }