不言不语

您现在的位置是: 首页 >  PHP  >  ThinkPHP

ThinkPHP

【thinkphp】之验证码

2020-05-21ThinkPHP
tp框架验证码的显示以及使用

手册地址:

https://www.kancloud.cn/manual/thinkphp5/154295


第一步:

composer require topthink/think-captcha 1.*


第二步:定义路由


Route::get('admin/captcha','admin/Admin/captcha');//验证码


第三步:控制器引入

use think\captcha\Captcha;

public function captcha(){


$captcha = new Captcha();

return $captcha->entry();


}


第四步:html显示验证码


 <img src="{:url('/admin/captcha')}" alt="" width="100" height="32" class="passcode" style="height:43px;cursor:pointer;" onclick="this.src=this.src+'?'">  


c368d5d7962f97d12fe407bf300691f.png


第五步:验证码配置参数

$config =    [
   // 验证码字体大小
   'fontSize'    =>    30,    
   // 验证码位数
   'length'      =>    3,  
   // 关闭验证码杂点
   'useNoise'    =>    false, ];$captcha = new Captcha($config);

例如:$captcha = new Captcha(['length'=>4]);//验证码4位


把配置参数传进去即可



文章评论