PHP TP5 实现验证码

时间:2021-08-05 10:26:04   收藏:0   阅读:20

  1.使用Composer安装扩展包

composer require topthink/think-captcha
官方的5.0版本的扩展库版本号都是1.*2.0版本均为ThinkPHP5.1版本专用。

2.模板内显示验证码图片

(1).
<div>{:captcha_img()}</div>
(2).
<div><img src="{:captcha_src()}" alt="captcha" /></div>

3.TP5中验证功能
$this->validate($data,[
    ‘captcha|验证码‘=>‘require|captcha‘
]);
或者手动验证
if(!captcha_check($captcha)){
 //验证失败
};

4.验证码实现点击无刷新更新
<img src="{:captcha_src()}" alt="captcha" onclick="this.src=‘{:captcha_src()}?id=‘+Math.random()+‘‘"/>
在img标签中加入标红内容即可实现无刷新更新

5.更改验证码配置

在TP5框架vendor/topthink/think-captcha/src/Captcha.php中修改具体配置
 
 

原文:https://www.cnblogs.com/ylf2000/p/15101649.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!