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