PHP--------ThinkPHP3.2 Verification Code use

Source: Internet
Author: User

thinkphp Framework Verification Code Path directory: thinkphp, Library, Think, Verify.class.php, as long as the controller to instantiate this class will be able to implement the function of the verification code.

:

Simple code:

    $Verify New thinkverify ();     $Verify->entry ();

The Verification code class will write the generated verification code to the session, through the session (' Verify_code ') to obtain the value, the comparison will be able to perform the role of verification code.

Parameters supported by the CAPTCHA:

You can set the relevant parameters for the generated captcha to achieve different display results. These parameters include:

Parameters Description
Expire Validity period of the verification code (in seconds)
Useimgbg Default to False if using background picture
FontSize Captcha font size (pixels) defaults to 25
Usecurve Whether to use the obfuscation curve by default to True
Usenoise Whether to add a noise by default to True
Imagew Verify that the code width is set to 0 for automatic calculation
Imageh Verify that the code height is set to 0 for automatic calculation
Length Verify number of code bits
Fontttf Specifies that the CAPTCHA font is randomly fetched by default
Usezh Whether to use Chinese verification code
Bg Verification code background color RGB array settings, e.g. array (243, 251, 254)
Sekey Encryption key for verification code
CodeSet Verification code character Set 3.2.1 new
Zhset Verification Code Character set (Chinese) 3.2.1 New

Putting the parameters into the corresponding variables in the instantiated object can change some of the validation codes.

Generate Verification Code

/ This code needs to be written in a separate controller method, convenient to call $Verify =     new  thinkverify (); // assigns a value to the specified variable parameter, adjusting the validation code effect $Verify->fontsize =; $Verify->length   = 3; $Verify false ; // Picture Output $Verify->entry ();

Call Verification Code

    <!-- the picture path here is the Controller method path in the TP frame.  -    <!-- Click on the image to get the picture path and stitching the new parameters, toggle the picture  -    <  onclick= "this.src=this.src+ ' & ' +math.random ()"  style= " Cursor:pointer; "      src= "Index.php?m=home&c=login&a=checkcode"/>

Verify the verification code

    // This can be written in the framework common function library function.php, and passed the parameter comparison, $code for the user's input verification code    function check_verify ($code$id = ")            {$verifynew  \think\verify ();             return $verify->check ($code$id);     }

Official Document Address: Http://document.thinkphp.cn/manual_3_2.html#verify

PHP--------ThinkPHP3.2 Verification Code use

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.