首先使用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;}
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号