This article describes the configuration and verification operation of captcha verification code in tp5 (thinkPHP5 framework). Share it for your reference, as follows:
1-Installation
composer require topthink/think-captcha 1.* -vvv
2-Configuration File
'captcha' => [ // Verification code character set 3. 'codeSet' => '2345678abcdefhijkmnpqrstuvwxyzABCDEFGHJKLMNPQRTUVWXY', // Verification code font size (px) 5. 'fontSize' => 28, // Whether to draw confusion curves 7. 'useCurve' => false, // Verification code picture height 9. 'imageH' => 50, // Verification code picture width 11. 'imageW' => 200, // The number of verification code digits is 13. 'length' => 4, // Whether to reset after verification is successful 15. 'reset' => true ],
3-html code
<div class="yzm"> <img src="{:captcha_src()}" class="verify" onclick="resVerify()" alt="Verification Code" /> <a href="javascript:resVerify();" rel="external nofollow" >Can't see clearly,Change one</a> </div>
or
<img src="{:captcha_src()}" class="verify" onclick="javascript:='{:captcha_src()}?rand='+()" >
4-Controller Verification at login
$captcha=input("captcha"); //verifyif (!captcha_check($captcha)){ exit(json_encode(array('status'=>0,'msg'=>'Verification code error'))); }
or
//Verification code Verification code$captcha = new Captcha(); if (!$captcha->check(input("captcha"))){ return $this->error("Verification code error"); }
More features and plug-ins Reference address:/he_he/thinkphp5/787173
For more information about thinkPHP related content, please check out the topic of this site:ThinkPHP Introduction Tutorial》、《Summary of the operation skills of thinkPHP templates》、《Summary of common methods of ThinkPHP》、《Codeigniter Introductory Tutorial》、《Advanced tutorial on CI (CodeIgniter) framework》、《Zend FrameWork Framework Introduction Tutorial"and"PHP template technical summary》。
I hope that the description in this article will be helpful to everyone's PHP programming based on the ThinkPHP framework.