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

伊谢尔伦
Release: 2016-11-26 13:59:55
Original
1102 people have browsed it

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();
}
Copy after login


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template