后台代码
public function getCapImg(){
$config = [
// 验证码字体大小(px)
'fontSize' => 20,
// 是否画混淆曲线
'useCurve' => false,
// 验证码图片高度
'imageH' => 44,
// 验证码图片宽度
'imageW' => 150,
// 验证码位数
'length' => 4,
// 验证成功后是否重置
'reset' => true
];
$captcha = new \think\captcha\Captcha($config);
return $captcha->entry();
}
HTML部分
去掉了所有的样式什么的剩下的
<img title="点击刷新验证码" src="<?=url('Login/getCapImg')?>" onClick="this.src='<?=url('Login/getCapImg')?>?d='+Math.random();" />
后台验证
$captcha = new \think\captcha\Captcha();
if( !( $captcha->check($arr['code']) ) ) {
// 校验失败
echo '验证码不正确';
}else{
echo "zhengqu";
}