The Yii Verification Code fails to be entered.

Source: Internet
Author: User

The Yii Verification Code fails to be entered.

Preface

When I recently made a request, I found that I entered the correct verification code, but all of them showed that the verification code was incorrect.

The final tracking code found that if the Model was verified separately before saving, the verification code will be generated again after the verification is completed.

ThenModel save The verification code will also be validated. During verification, the verification code has been re-generated, so it will not match

// If the verification code is used here, a problem occurs: $ model = new Test (); $ model-> validate (); $ model-> save ();
// This is the correct $ model = new Test (); // put the attribute to be verified and exclude the verification code field $ model-> validate (array ('test1 ', 'test2'); $ model-> save ()

We can seeframework/web/widgets/captcha/CCaptchaAction.phpYou can easily find problems.

<? Phpclass CaptchaAction extends CCaptchaAction {public function validate ($ input, $ caseSensitive) {$ code = $ this-> 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 ;} // here, if ($ session [$ name]> $ this-> testLimit & $ this-> testLimit> 0) is regenerated) {$ this-> getVerifyCode (true) ;}return $ valid ;}}

Summary

The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message, thank you for your support.

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.