Yii built-in CAPTCHA can basically meet most of the requirements, if you have special requirements for the verification code, you can customize the CAPTCHA, this is mainly through the expansion of ccaptchaaction to achieve, this example to customize a validation code function, randomly generated within 10 of addition and subtraction, The user needs to calculate the correct results to pass the validation.
This example is based on the previous example of the Yii Framework Development Tutorial (a) UI component Captcha sample, which is modified as follows
First in the Protected/components directory to create a mathcaptchaaction, overload Generateverifycode, RenderImage and other methods:
Class Mathcaptchaaction
extends ccaptchaaction
{
protected function Generateverifycode ()
{
return Mt_rand ((int) $this->minlength,
(int) $this->maxlength);
}
Public Function RenderImage ($code)
{
parent::renderimage ($this->gettext ($code));
}
protected function GetText ($code)
{
$code = (int) $code;
$rand =mt_rand (1, $code-1);
$op =mt_rand (0,1);
if ($op)
{return
$code-$rand. '+' . $rand;
} else
{return
$code + $rand. '-' . $rand;
}}}
Then modify Sitecontroller's rules to use the newly created mathcaptchaaction
The Public Function actions ()
{return
array (' Captcha ' =>array) ('
class ' => ' mathcaptchaaction ')
' minlength ' => 1,
' maxLength ' =>)
;
}
This example downloads: Http://www.imobilebbs.com/download/yii/CustomCaptchaDemo.zip
See a full set of tutorials: http://www.bianceng.cn/webkf/PHP/201301/35265.htm