1, in the Home module indexController.class.php, add the following code
<?phpnamespace Home\controller; UseThink\controller;classBookcontrollerextendsController { Public functionVerify_c () {$Verify=New\think\verify (); $Verify->fontsize = 18; $Verify->length = 4; $Verify->usenoise =false; $Verify->codeset = ' 0123456789 '; $Verify->imagew = 130; $Verify->imageh = 50; //$Verify->expire = +; $Verify-entry (); } Public functionimg () {$this-display (); }}
2. In the IMG view, add the following code
<Scripttype= "Text/javascript"src= "__public__/js/jquery2.0.3.min.js"></Script><Pclass= "Top15 captcha"ID= "Captcha-container"> <inputname= "Verify"width= "50%"Height= " the"class= "Captcha-text"placeholder= "Verification Code"type= "text"> <imgwidth= "+"class= "left15"Height= " the"alt= "Verification Code"src= "{: U (' Home/book/verify_c ', Array ())}"title= "Click to refresh"></P> <Scripttype= "Text/javascript"> $(function(){ varcaptcha_img= $('#captcha-container'). Find ('img'); varverifyimg=captcha_img.attr ("src"); Captcha_img.attr ('title', 'Click Refresh'); Captcha_img.click (function(){ if(Verifyimg.indexof ('?')>0){ $( This). attr ("src", Verifyimg+'&random='+math.random ()); }Else{ $( This). attr ("src", Verifyimg.replace (/\?. *$/,"')+'?'+math.random ()); } }); }) </Script>
This will allow you to display the verification code.
Reference Study website: http://blog.csdn.net/yafei450225664/article/details/40424025
Thinkphp 3.2 Add verification code how to Add.