Add the verification code plug-in and the Thinkphp Verification Code plug-in to thinkphp.
The principle and purpose of the Verification Code are well known.
Today, we will add the verification code plug-in to the tp framework.
We have added composer.
I found one on gitHub: https://github.com/gregwar/captcha. of course you can also use its own.
First, open composer. json.
Open xshell and go to this directory.
Run: composer install
Reinstall the dependency that is not found. Download captcha.
++
The box is added with automatic loading. We can directly introduce the space for use.
Use Gregwar \ Captcha \ CaptchaBuilder; // What does this sentence mean? Actually, it is a path,
Then instantiate
$ Builber = new CaptchaBuilder ();
$ Builder-> build (); // generate a verification code Image
$ Builder-> save('out.jpg '); // Save the verification code Image
inline ();?> "/> // Enter the image at the front end
$ Builder-> getPhrase (); // obtain the corresponding verification code
$ _ Session ['phrase '] = $ builder-> getPhrase (); // exists in the session
User input and Verification Code are compared
If ($ builder-> testPhrase ($ userInput )){
Echo "correct ";
} Else {
Echo "error ";
}
For more API, see: https://github.com/Gregwar/Captcha