Yii built-in CAPTCHA can basically meet most requirements, if you have special requirements for the verification code, you can customize the CAPTCHA, which
Mainly by extending the ccaptchaaction to achieve, this example customizes a verification code function, randomly generate 10 or less, with
The user needs to calculate the correct results to pass the validation.
This example is based on the example of the previous Yii Framework development tutorial (CAPTCHA) UI component, making the following modifications
First create a mathcaptchaaction in the Protected/components directory, overload the Generateverifycode,
RenderImage and Other methods:
Class Mathcaptchaactionextends 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 the Sitecontroller rules to use the newly created mathcaptchaaction
Public function actions () {return array (' Captcha ' =>array (' class ' = ' mathcaptchaaction ', ' minLength ' = 1, ' MaxLength ' = 10,)
The above is the content of the PHP Development Framework Yii Framework Tutorial (CAPTCHA) UI component sample, more about topic.alibabacloud.com (www.php.cn)!