PHP Development Framework Yii Framework Tutorial (a) UI component Captcha sample

Source: Internet
Author: User
Tags yii

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 ()),     
        );     

    }     

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.