Using thinkphp to implement verification code function

Source: Internet
Author: User

Many system logins have verification code, and if you use the thinkphp framework to build a website, verification code generation and validation is easier

1. Generate the Verification code

Thinkphp a method for generating verification codes


To use a verification code, you need to import the ORG.Util.Image class library and the ORG.Util.String class library in the Extended class library. We use a verify method in the module class to display the verification code:
    1. Public function Verify() {
    2. Import(' ORG. Util.image ');
    3. Image:: Buildimageverify ();
    4. }

 2. Validation code 
      1. if ($_session[ ' verify ' ]  != md5 ($_post[
      2.     $this ->error ( ' CAPTCHA error!) '
      3. }
Note that the verify name here depends on the value of the VerifyName parameter of your verification code.   Buildimagesverify method does not support the display of Chinese verification code, if you need to display the Chinese code, please use
Gbverify method, the parameters are as follows:

Usage examples:
    1. Public function Verify() {
    2. Import("ORG. Util.image ");
    3. Image::gbverify();}

The display effect is as follows



If the verification code cannot be displayed, please check:
Whether PHP has installed the GD library support;
Whether there is any output before the output (especially the UTF8 BOM header information output);
Whether the Image class library is imported correctly;
If it is a Chinese code check if there is a copy of the font file to the directory where the class library;

Using thinkphp to implement verification code 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.