imyfone-tp/captcha

A class of JWT captcha based on thinkphp5

Maintainers

Details

github.com/febhz/captcha

Source

Issues

Installs: 467

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 1

Forks: 0

Open Issues: 0

Type:think-cache

v1.0.0 2021-03-22 11:06 UTC

This package is auto-updated.

Last update: 2024-04-22 21:04:47 UTC


README

  • PHP >= 5.6

介绍

前后端分离使用的验证码

安装

composer require imyfone-tp/captcha

使用

发送验证码

//
use imyfone\TheCaptcha;
//自定义配置,可以用默认的不配置
$config=[
	'codeSet'  => '123456',
    // 验证码字符集合
    'expire'   => 1800,
    // 使用背景图片
    'fontSize' => 25,
    // 中文验证码字符串
    'useImgBg' => false,

    'length'   => 4,
    // 验证码位数
    'fontttf'  => '',
    // 验证码字体,不设置随机获取
];
$id = 'hello';//id随便定义一个,也可以不定义
$captcha = new TheCaptcha($config);
return $captcha->getEntry($id);
//验证操作
use imyfone\TheCaptcha;

$id = 'hello';//id与上面定义的id一致
$uniqid = $_POST['uniqid'];
$code = $_POST['code'];
$captcha = new TheCaptcha();
if($captcha->checkCaptcha($uniqid,$code,$id) === true){
	# 验证成功
}
else{
    # 验证失败
}