对我们开发人员来说,都知道验证码可以有效防止恶意破解密码发送登陆请求,不断的登陆尝试,如表单方面可防止注入、垃圾内容灌水等。现在腾巢网络技术小编分享在网站登陆时如何采用ThinKphp5.0实现验证码验证。

ThinKphp5.0验证码的用法
HTML代码
<div class="form-group has-feedback"> <img src="{:captcha_src()}" id="codeimage" class="refresh_verify" alt="验证码"/> <span class="refresh_verify">看不清,换一张验证码</span> </div>
JS代码
$('.refresh_verify').click(function () { $('#codeimage').attr("src", '{:captcha_src()}'); });
看不清,单击换一张
PHP代码
$request = Request::instance(); $code = $request->param('captcha'); $captcha = new Captcha(); if (!$captcha->check($code)) { $this->error('验证码错误'); }
命名空间
use think\Request; use think\captcha\Captcha;