Implementation of thinkphp Verification code

Source: Internet
Author: User

Two Verification code verification implementation, a direct in the form form submit button implementation validation, a use of Ajax pass parameters to implement validation:

1, directly in the form form submit button implementation verification, in the controller VerifyController.class.php write the following code:

Namespace Home\controller;use Think\controller;class Verifycontroller extends Controller {public    function index () {        $this->display ();    }    Public Function Checklogin () {        $verify =new \think\verify ();        $code =i (' post.verify ');//The form Verification code        if ($verify->check ($code)) {            $this->success (' captcha correct ');        } else{            $this->error (' Verification Code error ');        }    }    Public Function Verify ()    {        //Instantiate Verify object        $verify = new \think\verify ();        Configure the CAPTCHA parameter        $verify->fontsize = +;     Captcha Font size        $verify->length = 4;        Verify the number of code digits        $verify->imageh =;       Verification code Height        $verify->useimgbg = true;   Turn on the captcha background        $verify->usenoise = false;  Turn off captcha noise        $verify->entry ();}    }

The code in view verify/index.html is as follows:

<! DOCTYPE html>

2, using the Ajax pass parameter implementation validation, the code in the controller VerifyController.class.php is as follows:

Namespace Home\controller;use Think\controller;class Verifycontroller extends Controller {public    function index () {        $this->display ();    }    Public Function Checklogin () {        $verify =new \think\verify ();        $code =$_post[' code '];//ajax verification code get        if ($verify->check ($code)) {            $this->ajaxreturn (1);        } else{            $this->ajaxreturn (0);        }    }    Public Function Verify ()    {        //Instantiate Verify object        $verify = new \think\verify ();        Configure the CAPTCHA parameter        $verify->fontsize = +;     Captcha Font size        $verify->length = 4;        Verify the number of code digits        $verify->imageh =;       Verification code Height        $verify->useimgbg = true;   Turn on the captcha background        $verify->usenoise = false;  Turn off captcha noise        $verify->entry ();}    }

The code in view verify/index.html is as follows:

<! DOCTYPE html>

In the 2nd method, do not forget to download the Jquery.min.js file: http://www.jq22.com/jquery-info122

To configure the address in profile common/conf/config.php:

return Array (/      * Address replace *    /' tmpl_parse_string ' =>array (          ' __js__ ' =>__root__. /public/js ',    ),);

Implementation of thinkphp Verification code

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.