• thinkphp5 自定义验证码使用


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

    public function verify(){
    $captcha = new hinkcaptchaCaptcha();
    //使用中文验证码
    $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

    我是一名大学生,喜欢学习技术,希望和你一起进步。加油
  • 相关阅读:
    【Python】python模块加载
    【Python】Django学习一:第一个Django程序
    【Python】Python PYQT4 GUI编程与exe打包
    XGBoost 输出特征重要性以及筛选特征
    数据挖掘博客收集
    python 多线程
    python 统计学的各种检验
    数据挖掘-逻辑回归解析
    Centos7 教程收集ing
    数据挖掘比赛优秀经验贴-收集ing
  • 原文地址:https://www.cnblogs.com/lvhaiqing/p/10063186.html
Copyright © 2020-2023  润新知