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