A simple method of using verification code in thinkphp

Source: Internet
Author: User
This paper describes the simple use of verification code in thinkphp. Share to everyone for your reference, as follows:

First generate the verification code, in the action file, directly call the thinkphp provided in the method can be generated, to ensure that the extension of PHP GD2

As follows:

Class Useraction Model extends model{/** * Display Verification Code information */Public Function verify () {     ob_clean ();///Erase (Erase) output buffer, i.e. empty the front Out, usually the verification code does not display, you can consider the issue of     import (' ORG. Util.image ');     Image::buildimageverify ();  }}

At the same time, the value of the generated verification code is saved with the session:

Copy the Code code as follows:

$_session[' Verify ']


Note: The value that was saved after MD5 is encrypted .

In the corresponding TPL file, the verification code is called, using the following method:

Copy the Code code as follows:

The user submits the past verification code, which needs to be MD5 encrypted, compared with the saved session value , namely:

Determine if MD5 ($_post[' verify ') is equal to $_session[' verify '].

To complete the basic use of verification code

It is hoped that this article is helpful to the PHP program design based on thinkphp framework.

The above introduces the simple use of verification code in thinkphp, including the content of the contents, I hope that the PHP tutorial interested in a friend helpful.

  • 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.