首先使用composer安装
composer require topthink/think-captcha=2.0.*
页面中使用
<input name="code" lay-verify="required" placeholder="请输入验证码" type="text" class="layui-input">
<br><br>
<img src="{:captcha_src()}" alt="captcha" onclick="this.src=this.src+'?'+Math.random()"/>
PHP中使用
public function login()
{
if (\think\facade\Request::post()){
$data = input('post.');
$check = $this->checkCode($data['code']);
if (!$check){
$res['status'] = 0;
return json($res);
}else{
$res['status'] = 1;
return json($res);
}
}else{
return $this->fetch();
}
}
public function checkCode($code){
//验证码判断
if(captcha_check($code)){
return true;
}
else{
return false;
}
}