Code Monkey home page Code Monkey logo

captcha's Introduction

captcha

tp验证码独立版

安装

composer require ilbsfx/captcha

配置参数(可选)

参数 描述 默认
codeSet 验证码字符集合
math 使用算术验证码 false
useZh 使用中文验证码 false
zhSet 中文验证码字符串
useImgBg 使用背景图片 false
fontSize 验证码字体大小(px) 25
useCurve 是否画混淆曲线 true
useNoise 是否添加杂点 true
imageH 验证码图片高度,设置为0为自动计算 0
imageW 验证码图片宽度,设置为0为自动计算 0
length 验证码位数 5
fontttf 验证码字体,不设置是随机获取
bg 背景颜色 [243, 251, 254]

使用

use Colton\Captcha\CaptchaBuilder;

//(可选参数)
$config = [
    //验证码位数
    'length'   => 5,
    // 验证码字符集合
    'codeSet'  => '2345678abcdefhijkmnpqrstuvwxyzABCDEFGHJKLMNPQRTUVWXY',
    // 是否使用中文验证码
    'useZh'    => false,
    // 是否使用算术验证码
    'math'     => false,
    // 是否使用背景图
    'useImgBg' => false,
    //验证码字符大小
    'fontSize' => 25,
    // 是否使用混淆曲线
    'useCurve' => true,
    //是否添加杂点
    'useNoise' => true,
    // 验证码字体 不设置则随机
    'fontttf'  => '',
    //背景颜色
    'bg'       => [243, 251, 254],
    // 验证码图片高度
    'imageH'   => 0,
    // 验证码图片宽度
    'imageW'   => 0
];

$captcha = new CaptchaBuilder($config);

// 获取验证码key
$_SESSION['key'] = $captcha->getCodeKey();

// 输出验证码图片
$captcha->output();


// 验证验证码是否正确
$userInput = $_POST['code'];
$res = $captcha->check($userInput, $_SESSION['key']);
if ($res === true) {
    // 验证码正确
} else {
    // 验证码错误
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.