Add the verification code plug-in and the Thinkphp Verification Code plug-in to thinkphp.

Source: Internet
Author: User
Tags composer install

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

 




 

Related Article

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.