分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

thinkphp5 自定义验证码使用

发布时间:2023-09-06 02:25责任编辑:白小东关键词:thinkphp验证码

控制器【https://blog.csdn.net/John_rush/article/details/80169702】

public function verify(){
???????$captcha = new \think\captcha\Captcha();
???????//使用中文验证码
???????$captcha->useZh = true;
???????//验证码过期时间(s)
???????$captcha->expire =1800;
???????//是否画混淆曲线
???????$captcha->useCurve =true;
???????//是否添加杂点
???????$captcha->useNoise = true;
???????//验证码位数
???????$captcha->length = 4;
???????//验证成功后是否重置
???????$captcha->reset = true;
???????// 设置验证码字符
???????$captcha->zhSet = ‘们以我到他会作时要动国产的一是工就年阶义发成部民可出能方进在了不和有大这‘;
???????return $captcha->entry();
???}
页面调用
<img src="{:url(‘common/verify‘)}" alt="captcha" onclick="this.src=‘{:url(‘common/verify‘)}?seed=‘+Math.random()" height="42" id="captcha" />

点击刷新
onclick="this.src=‘{:url(‘common/verify‘)}?seed=‘+Math.random()"
验证
//使用TP5的内置验证功能,添加captcha验证规则即可

$this->validate($data,[
???‘captcha|验证码‘=>‘require|captcha‘
]);

//或者手动验证

if(!captcha_check($captcha)){
//验证失败
};

//用Captcha类的check方法检测验证码的输入是否正确,例如,下面是封装的一个验证码检测的函数:

// 检测输入的验证码是否正确,$code为用户输入的验证码字符串,$id多个验证码标识
function check_verify($code, $id = ‘‘){
???$captcha = new Captcha();
???return $captcha->check($code, $id);
}


---------------------
作者:opfano_o
来源:CSDN
原文:https://blog.csdn.net/qazx123q/article/details/79724682

thinkphp5 自定义验证码使用

原文地址:https://www.cnblogs.com/lvhaiqing/p/10063186.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved