Thinkphp verification code implementation and problems

Source: Internet
Author: User
Verification code is an inaccessible technology on the current website. Message, comment, verification code is required all the time to prevent users from refreshing comments and leaving messages. First, User violations are restricted.

Verification code is an inaccessible technology on the current website. Message, comment, verification code is required all the time to prevent users from refreshing comments and leaving messages. First, User violations are restricted. second, website security is protected. thinkphp comes with the verification code function, which is in Chinese and English. Today, I will explain how thinkphp implements the English letter verification code.

Thinkphp's official manual also clearly states that the verification code was written according to the manual method when I wrote the verification code for the last project, but the verification code cannot be displayed, finally, I checked the manual and the code again and again, but I couldn't find the problem. well, let's get the code first.

Methods in the manual:


To use the verification code, you must import the ORG. Util. Image class library and ORG. Util. String class library in the extended class library. We add a verify method to the module class for display.

Public function verify (){

Import ("ORG. Util. Image ");

Image: buildImageVerify ();

}

Each time a verification code is generated, the md5 string information of the verification code is recorded through the SESSION. Therefore, check whether the verification code is correct, we only need to use the following code in Action:

If ($ _ SESSION ['verify ']! = Md5 ($ _ POST ['verify ']) {

$ This-> error ('verification code error! ');

}

Note that the verify name here depends on the value of the verifyName parameter of your verification code.

View:


After the verification code is written, Let's summarize the reasons,

1: If the returned information is undefined, do you need to check whether the introduced verification code class in the controller has been correctly introduced? the general syntax is import ("ORG. Util. Image ");

2: This step is a small detail, and it is a test of the attention of a programmer. The last time I delayed the afternoon due to this problem, the verification code was rejected, the method for generating the verification code is a bunch of garbled characters and there are no errors in each step. at last, I thought of a small detail: I changed the file encoding format to UTF-8 without BOM encoding format, in this way, there is no error. sometimes you need to be careful when writing code. Otherwise, you can scratch your head.

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.