这篇文章主要和大家分享了ThinkPHP5的验证码的实现方法,有一定的参考价值,感兴趣的朋友可以看看。
1、首先确认文件夹\vendor\topthink\think-captcha存在

2、显示验证码的方法,我这里是写在:\application\admin\controller\login.php
//显示验证码
public function show_captcha(){
$captcha = new \think\captcha\Captcha();
$captcha->imageW=121;
$captcha->imageH = 32; //图片高
$captcha->fontSize =14; //字体大小
$captcha->length = 4; //字符数
$captcha->fontttf = '5.ttf'; //字体
$captcha->expire = 30; //有效期
$captcha->useNoise = false; //不添加杂点
return $captcha->entry();
}3、模板文件\application\admin\view\Login\index.html中这样引用验证码









