Home > Article > PHP Framework > ThinkPHP implements clicking on the picture to refresh the verification code
This article introduces the method of using the thinkphp framework to refresh the verification code by clicking on the image. I hope it will be helpful to friends who are learning thinkphp!
ThinkPHP implements clicking on the image to refresh the verification code
This type of verification code function refresh function involves two refreshes , one is to refresh by clicking on the verification code image, and the other is to refresh by entering the wrong verification code. Of course, don’t mention refreshing it yourself, it will definitely be refreshed.
(Recommended tutorial: thinkphp tutorial)
The thinkPHP framework has a built-in verify.class.php verification class. When we do verification code verification, it is very simple. Two verification formats are provided here, one is pure number, and the other is the system default. The methods inside are all methods written in the login controller. The specific code is as follows
//第一种默认的验证码 public function captcha(){ $config = array( 'length' => 4, // 验证码位数 ); $Verify = new \Think\Verify($config); $Verify->entry(); }
The other one
//第二种默认的验证码 function show_verify($config=''){ if($config==''){ $config=array( 'codeSet'=>'1234567890', 'fontSize'=>30, 'useCurve'=>false, 'imageH'=>60, 'imageW'=>240, 'length'=>4, 'fontttf'=>'4.ttf', ); } $verify=new \Think\Verify($config); return $verify->entry(); }
Display the HTML code of the verification code image
<div class="form-group"> <input type="text" class="form-control" placeholder="验证码" required="" name="verify" > <img class="verify" src="{:U('Admin/Login/show_verify')}" title="点击更换" onclick="this.src+='';"> </div>
The picture onclick event can complete the refresh of the verification code
For more ThinkPHP framework tutorials, please pay attention to PHP Chinese website!
The above is the detailed content of ThinkPHP implements clicking on the picture to refresh the verification code. For more information, please follow other related articles on the PHP Chinese website!