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.