Captcha (fully automatic distinction between computer and human Turing Test-completely Automated public Turing test to tell Computers and humans Apart) is commonly known as the authentication Code, is a public automatic program that distinguishes users from computers and people. In the CAPTCHA test, the computer that serves as the server automatically generates a problem to be answered by the user. This problem can be generated and judged by the computer, but it must be solved only by humans. Because the computer cannot answer the CAPTCHA problem, the user who answers the question can be considered human.
The YII framework provides classes Ccaptcha and ccaptchaaction to support authentication codes, and it should be noted that this functionality needs to be supported by the PHP GD extension and can be queried through the requirements application of Yii:
If warning is displayed, you can open this feature by installing the GD extension Library and modifying php.ini.
Ccaptcha also provides method ccaptcha::checkrequirements () to detect whether the GD library is installed.
This example adds CAPTCHA functionality to the Starrating sample of the Yii Framework Development Tutorial (a) UI component, which is valid only if the input verification code is correct and avoids automatic scoring by the machine.
The first is to modify the Datamodel, add a property Verifycode the authentication code that holds the user input, and add ccaptchavalidator validation to it.
Class
Datamodel extends Cformmodel
{public
$rating;
public $verifyCode;
Public function rules ()
{return
array (
' Rating,verifycode ', ' safe '),
Array (' Verifycode ', ' captcha ', '
allowempty ' =>! Ccaptcha::checkrequirements ()),
);
}