Yii verification code implementation

Source: Internet
Author: User
This article describes the implementation of the yii verification code, which is just a small example of the application by the Author. it is also available on the internet. to sum up, I hope to help Yii enthusiasts who need it. 1. I use user logon, so add the following in sitecontroller:

This article describes the implementation of the yii verification code, which is just a small example of the application by the Author. it is also available on the internet. to sum up, I hope to help Yii enthusiasts who need it. 1. The author uses user logon, so add the following code in sitecontroller:

?
123456789101112 Publicfunctionactions () {returnarray (// captcha action renders the CAPTCHA image displayed on the contact page 'captcha '=> array ('class' => 'ccaptchaaction ', 'backcolor' => 0 xFFFFFF, // background color 'minlength' => 4, // The shortest is 4 bits 'maxlength' => 4, // The length is 4-bit 'Transparent' => true, // it is displayed as transparent. when this option is disabled, the background color is displayed ),);


2. add the following code to the form File (view file such as login. php ):

?
1234567891011 LabelEx ($ model, 'verifycode');?> Widget ('ccaptcha ');?> TextField ($ model, 'verifycode');?> Enter verification code Error ($ model, 'verifycode');?>


3. add the following code to the Loginform model (LoginForm. php) to add attribute fields. Otherwise, an error is returned (non-existent attribute)

?
12345 Public $ username; public $ password; public $ verifyCode; public $ rememberMe; private $ _ identity;


We can see the verification code through the above operation, but during the operation, we will find that the verification code is still acceptable without being entered, because we have not specified that the verification is required, in the LoginForm. in php, add array ('verifycode', 'required') to specify the required parameters. if the verification code is missing, it will be shown in:

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.