PHPackages                             juhui/php-captcha - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. juhui/php-captcha

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

juhui/php-captcha
=================

A simple and flexible PHP captcha library

v1.0.0(1y ago)07MITPHPPHP &gt;=7.2.5

Since Dec 20Pushed 1y ago1 watchersCompare

[ Source](https://github.com/327111804/php-captcha)[ Packagist](https://packagist.org/packages/juhui/php-captcha)[ RSS](/packages/juhui-php-captcha/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

PHP Captcha
===========

[](#php-captcha)

一个简单而灵活的 PHP 验证码库。

安装
--

[](#安装)

```
composer require juhui/php-captcha
```

环境要求
----

[](#环境要求)

- PHP &gt;= 7.2.5
- GD 扩展

功能特点
----

[](#功能特点)

- 支持中文和英文验证码
- 支持数学运算验证码
- 支持自定义字体
- 支持自定义验证码样式
- 支持 base64 输出
- 简单易用的 API

使用方法
----

[](#使用方法)

### 基本使用

[](#基本使用)

```
// 生成验证码
$captcha = captcha();

// 验证验证码
if (captcha_check($_POST['code'])) {
    // 验证码正确
} else {
    // 验证码错误
}
```

### 获取 base64 图片和文本

[](#获取-base64-图片和文本)

```
// 获取验证码的 base64 图片和文本
$result = captcha_base64();
echo $result['img'];  // base64 图片
echo $result['code']; // 验证码文本
```

### 自定义配置

[](#自定义配置)

```
$config = [
    // 验证码位数
    'length'   => 4,
    // 验证码字符集合
    'codeSet'  => '2345678abcdefhijkmnpqrstuvwxyzABCDEFGHJKLMNPQRTUVWXY',
    // 验证码字体大小(px)
    'fontSize' => 18,
    // 是否画混淆曲线
    'useCurve' => true,
    // 验证码图片高度
    'imageH'   => 38,
    // 验证码图片宽度
    'imageW'   => 106,
    // 验证码过期时间（s）
    'expire'   => 1800,
    // 是否使用中文验证码
    'useZh'    => false,
    // 是否使用背景图片
    'useImgBg' => false,
    // 是否添加杂点
    'useNoise' => true,
    // 验证码字体，不设置随机获取
    'fontttf'  => '',
    // 背景颜色
    'bg'       => [255, 255, 255],
    // 验证码类型（是否使用算术验证码）
    'math'     => false,
    // 透明度
    'alpha'    => 0,
];

// 使用自定义配置生成验证码
$captcha = captcha($config);
```

自定义字体
-----

[](#自定义字体)

将 TTF 字体文件放在 `vendor/juhui/php-captcha/assets/fonts` 目录下即可。

许可证
---

[](#许可证)

MIT

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance40

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

514d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9cc5faeea7bffd1cca6bfeb9112e1b759622853978694b0a606d8b6e0d11f296?d=identicon)[327111804](/maintainers/327111804)

### Embed Badge

![Health badge](/badges/juhui-php-captcha/health.svg)

```
[![Health](https://phpackages.com/badges/juhui-php-captcha/health.svg)](https://phpackages.com/packages/juhui-php-captcha)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
