PHP Development Framework Yii Framework tutorial (UI component Captcha example)

Source: Internet
Author: User
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)!

  • 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.