zoukankan      html  css  js  c++  java
  • tp6 使用/自定义验证码

    使用tp6验证码需要先引入

    composer require topthink/think-captcha

    自定义验证码 在项目模块下新建控制器

    <?php
    
    namespace appadmincontroller;
    
    use thinkcaptchafacadeCaptcha;
    
    class Verify
    {
        public function index()
        {
            return Captcha::create();
        }
    }

    如果需要使用自己的配置,则在config/captcha.php

    <?php
    // +----------------------------------------------------------------------
    // | Captcha配置文件
    // +----------------------------------------------------------------------
    
    return [
        //验证码位数
        'length'   => 5,
        // 验证码字符集合
        'codeSet'  => '2345678abcdefhijkmnpqrstuvwxyzABCDEFGHJKLMNPQRTUVWXY',
        // 验证码过期时间
        'expire'   => 1800,
        // 是否使用中文验证码
        'useZh'    => false,
        // 是否使用算术验证码
        'math'     => false,
        // 是否使用背景图
        'useImgBg' => false,
        //验证码字符大小
        'fontSize' => 25,
        // 是否使用混淆曲线
        'useCurve' => true,
        //是否添加杂点
        'useNoise' => true,
        // 验证码字体 不设置则随机
        'fontttf'  => '',
        //背景颜色
        'bg'       => [243, 251, 254],
        // 验证码图片高度
        'imageH'   => 0,
        // 验证码图片宽度
        'imageW'   => 0,
    
        // 添加额外的验证码设置
        'verify' => [
             'length'=>4,
            'useCurve' => false,
            //是否添加杂点
            'useNoise' => false,
    
         ],
    ];
    

      然后修改自定义验证码控制器方法为

     return Captcha::create('verify');

    前端使用

    <div>
    <img src="{:url('verify/index')}"  onclick='this.src="{:url('verify/index')}?"+Math.random();'  width="100" height="43" class="admin-captcha" alt="">
    </div>
    

      

  • 相关阅读:
    1032. Sharing (25)
    1031. Hello World for U (20)
    1030. Travel Plan (30)
    1029. Median (25)
    1028. List Sorting (25)
    1026. Table Tennis (30)
    win10 tortoiseSVN文件夹及文件图标不显示解决方法
    qrcode.react和jquery.qrcode生成二维码
    js来获取所有屏幕适配的总结
    handsontable整理
  • 原文地址:https://www.cnblogs.com/aln0825/p/12609862.html
Copyright © 2011-2022 走看看