生成
use think\captcha\Captcha; public function verify(){ $config = [ // 验证码字体大小 'fontSize' => 30, // 验证码位数 'length' => 3, // 关闭验证码杂点 'useNoise' => false, ]; ob_clean(); $captcha = new Captcha($config); return $captcha->entry(); }
页面显示
<a href="javascript:;"><img src="/verify" onclick="javascript:this.src=this.src+'?time='+Math.random()" ></a>
验证
$captcha = new Captcha(); if (!$captcha->check($data['code'])){ return jserror("验证码错误"); }