页面代码
<form class="" action="{:url('check')}" method="post">
<p>
验证码:
<!-- {:captcha_img()} -->
<img src="{:captcha_src()}" alt="">
</p>
<p>
请输入验证码:
<input type="text" name="code" id="">
</p>
<p>
<input type="submit" value="提交">
</p>
</form>
注:即使用{:captchasrc()}标签直接使用验证码,或通过{captcha_img()}使用验证器。
使用效果
在控制器中对输入验证码正误进行判断
//通过Input方法获取post方法传递的code变量值
$code = input("post.code");
//使用captcha_check()方法对输入的验证码进行判断
if (captcha_check($code)) {
echo "okok";
}else {
echo "error";
}
注:也可以在配置文件中添加验证码的应用配置自定义验证码的形式(修改参数可以参照验证码类中的属性值app\vendor\topthink\think-captcha\src\Captcha.php)
//使用配置(app\config)
//应用配置
'captcha'=>[
//验证码的字符集合
"codeSet"=>'123',
//使用中文
'useZh'=>true,
// 验证码的中文字符集合
'zhSet'=>'吴敬昌'
],