Generate/Verify CAPTCHA function with thinkphp

Source: Internet
Author: User

First understand some of the functions in the parent class Verity.class.php (thinkphp/library/think/verity.class.php)

1:check () Verify that the verification code is correct

2:entry () output The verification code and save the value of the verification code in the session

3:authcode () Encryption Verification code (this method is called in the Check () method)

The controller generates the CAPTCHA code:

//Verification Code    functionverifyimg () {//Verification Code Configuration        $cfg=Array(           ' Imageh ' = 30,//Verification Code Picture height' Imagew ' = 100,//Verification Code Picture width' FontSize ' = 15,//captcha font size (px)' Length ' = 4,//Verify number of code bits' Fontttf ' = ' 4.ttf ',//captcha font, not set random get        ); //instantiate the Verify class to automatically call the constructor and pass the $cfg information to $config        $verify=NewVerify ($cfg); $verify-entry();//Output Verification Code}

Verification code displayed at front desk

<!-- Group/Controller/method --
<src= "<{$smarty. const.__controller__}>/verifyimg" = "this.src= ' <{$smarty. const.__controller__}>/verifyimg/' +math.random ()" alt = "Verification Code" />

Controller calibration Code (take login as an example)

//Login    functionLogin () {//two logic: show, collect        if(!Empty($_post)) {            $verify=NewVerify (); //Receive Verification Code            $captcha=$_post[' Captcha ']; //Check () method check Verification code            if($verify-Check($captcha)) {                EchoCorrect; }Else{                EchoError; }        }       //call The View view       $this-display (); }

Use thinkphp to implement build/verify Captcha function

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.