hectorqin / think-captcha

think-captcha

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

think-captcha

验证码类库 For ThinkPHP5.1 和 ThinkPHP6.0 基于top-think/think-captcha 修改而来

安装

composer require hectorqin/think-captcha

配置

修改 config/captcha.php 配置文件,支持多个验证码配置,也支持实例化时传入配置进行覆盖(优先级最高)

使用

模板里输出验证码

<div>{:captcha_img()}</div>

或者

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

上面两种的最终效果是一样的

接口输出验证码

class CaptchaController
{
    public function index($id = "", $configName = "")
    {
        $captcha = new Captcha(); // 可传入数组配置进行覆盖<优先级最高>
        return $captcha->entry($id, $configName); // 可选择配置模式
    }
}

控制器里验证

使用TP5的内置验证功能即可

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

或者手动验证

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

About

think-captcha

License:Other


Languages

Language:PHP 100.0%