Resolve Yii input correct CAPTCHA verification failure

Source: Internet
Author: User
Tags yii
When a requirement is made, it is found that the correct code is entered, but the verification code is wrong.

The last trace code found that if the Model was save previously verified separately, the verification validate code will be regenerated after the verification is completed.

Then in our Model save , we will also validate verify that the verification code has been regenerated, so it will not match

// 如果这里用到了验证码,就会出问题$model = new Test();$model->validate();$model->save();
// 这样是正确的$model = new  Test();// 把需要验证的 attribute 放进去,排除验证码字段$model->validate(array('test1','test2'));$model->save()

We can see framework/web/widgets/captcha/CCaptchaAction.php that it's easy to find the problem.


  
   getVerifyCode();        $valid = $caseSensitive ? ($input === $code) : !strcasecmp($input, $code);        $session = Yii::app()->session;        $session->open();        $name = $this->getSessionKey() . 'count';        if (!Yii::app()->request->isAjaxRequest) {            $session[$name] = $session[$name] + 1;        }                // 这里会重新生成        if ($session[$name] > $this->testLimit && $this->testLimit > 0) {            $this->getVerifyCode(true);        }        return $valid;    }}

The above is introduced to solve the Yii input correct verification code verification failure, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.