Tp3.1.3 Verification Code principles and Solutions

Source: Internet
Author: User
Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn ThinkPHP3.1.3. In this document, the description of the verification code is relatively simple. Here I will talk about my own understanding of the TP verification code.
ThinkPHP has its own verification code API, which is easy to call. The Code is as follows: Public function verify(){
import('ORG.Util.Image');
Image::buildImageVerify();
}
The Calling principle is relatively simple, mainly in ThinkPHP \ Extend \ Library \ ORG \ Util \ Image. class. php and ThinkPHP \ Extend \ Library \ ORG \ Util \ String. class. php.
It mainly calls Image. class. the static method buildImageVerify () in php, and then use String. class. generate a verification code in the php class, then generate an image through php, and return it to the browser as the header.

The core code is as follows (the tp version I used has a bug in this function. The verification code is case sensitive and I changed it myself ): import('ORG.Util.String');
$randval = String::randString($length, $mode);
session($verifyName, md5(strtolower($randval)));
The generated verification code is stored in $ randval as a session, and the default value of $ randval is verify.

If it is really easy to verify the verification code in the background every time you submit the request, you can determine whether the md5 value is the same. However, in terms of human-computer interaction, such a design is inconvenient for users. The common Verification Code mechanism is to check whether the verification code is correct immediately on the front-end after the verification code is entered.
The appendix provides the general design solution code, which is proposed from the project and cannot be used directly. It is for reference only.
I hope you can give me some advice on cainiao ~

Tpverification code solution. Zip (2.71 KB download: 53 times)

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

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.