PHPackages                             phpu/think-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. phpu/think-captcha

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

phpu/think-captcha
==================

thinkphp6图片验证码

v2.0.2(4y ago)63381Apache-2.0PHPPHP &gt;=7.1.0

Since Dec 23Pushed 4y ago1 watchersCompare

[ Source](https://github.com/liujiawm/think-captcha)[ Packagist](https://packagist.org/packages/phpu/think-captcha)[ RSS](/packages/phpu-think-captcha/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (1)Versions (6)Used By (0)

thinkcaptcha
============

[](#thinkcaptcha)

thinkphp6图片验证码

安装
--

[](#安装)

php版本要求 &gt;=7.1.0

composer

```
composer require phpu/think-captcha

```

如果项目未开启SESSION,则需要开启，开启方式参考[thinkphp6完全开发手册中杂项之SESSION](https://www.kancloud.cn/manual/thinkphp6_0/1037635)

require
-------

[](#require)

- mbstring
- gd
- topthink/framework ^6.0.0

### 注意：验证码不支持多字节字符

[](#注意验证码不支持多字节字符)

[![](https://camo.githubusercontent.com/01d336c44644494b1bb8ffc24a8f7a7f7d352de6a9925239799b08ea798afcf9/68747470733a2f2f696d616765732e67697465652e636f6d2f75706c6f6164732f696d616765732f323032312f303130352f3031313632365f37643562626163615f313234373632312e706e67)](https://camo.githubusercontent.com/01d336c44644494b1bb8ffc24a8f7a7f7d352de6a9925239799b08ea798afcf9/68747470733a2f2f696d616765732e67697465652e636f6d2f75706c6f6164732f696d616765732f323032312f303130352f3031313632365f37643562626163615f313234373632312e706e67)

[![](https://camo.githubusercontent.com/eead7d0191d6f3add63cc81412caeb390365902d6150fcb71f2c8be5ab065361/68747470733a2f2f696d616765732e67697465652e636f6d2f75706c6f6164732f696d616765732f323032312f303130352f3031313633365f31633865376631645f313234373632312e706e67)](https://camo.githubusercontent.com/eead7d0191d6f3add63cc81412caeb390365902d6150fcb71f2c8be5ab065361/68747470733a2f2f696d616765732e67697465652e636f6d2f75706c6f6164732f696d616765732f323032312f303130352f3031313633365f31633865376631645f313234373632312e706e67)

[![](https://github.com/liujiawm/think-captcha/raw/main/test1.png)](https://github.com/liujiawm/think-captcha/raw/main/test1.png)

[![](https://github.com/liujiawm/think-captcha/raw/main/test2.png)](https://github.com/liujiawm/think-captcha/raw/main/test2.png)

使用方法
----

[](#使用方法)

控制器文件use phpu\\facade\\ThinkCaptcha;

```
use phpu\facade\ThinkCaptcha;

```

### 输出验证码图片

[](#输出验证码图片)

验证码显示控制器

```
    public function captcha(){
        return ThinkCaptcha::printImg(); // png图片
        // return ThinkCaptcha::printBase64(); // Base64
    }

```

### 验证

[](#验证)

验证码验证控制器

```
    public function check($code){

        if (false === ThinkCaptcha::check($code)){
            return response('验证码输入错误',200);
        }else{
            return response('验证码输入正确',200);
        }

    }

```

更多说明
----

[](#更多说明)

如果创建验证码时使用独立的key

`ThinkCaptcha::printImg('test') // 'test'是识别key,限数字和字母`

那么验证时也需要传入同名key

`ThinkCaptcha::check($code,'test') // 'test'是识别key,限数字和字母`

默认验证完后不论成功还是错误都会删除验证码数据，如果验证完后不删除

`ThinkCaptcha::check($code,'test',0) // 0表示不删除`

或者，只有在验证成功后才删除

`ThinkCaptcha::check($code,'test',1) // 1表示验证成功后才删除`

当然，验证时也可以设置验证码过期时间，默认1800秒(30分钟内有效)

`ThinkCaptcha::check($code,'test',2,3600) // 1小时内有效`

独立配置
----

[](#独立配置)

配置文件中提供独立配置，

如果无效果建议将配置文件config.php改名为`phpu_captcha.php`移入项目配置目录内！

使用`configure()`配置，参数是配置文件一级数组的索引，默认为`default`

例：

```
/**
 * 配置文件中提供独立配置，
 * 如果无效果建议将配置文件config.php改名为phpu_captcha.php移入项目配置目录内！
 */
    public function captcha(){
        return ThinkCaptcha::configure('sign')->printImg();
    }

```

配置文件

```
     return [
         // 默认配置
         'default' => [
             'char_preset' => '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', // 预设字符集，不支持多字节字符
             'length'     => 5, // 验证码位数
             'width'      => 0, // 图片宽
             'height'     => 0, // 图片高
             'font_size'   => 48, // 验证码字体大小(px)
             'bg'         => [243, 251, 254], // 背景颜色
             'use_curve'   => true, // 是否画混淆曲线
             'use_noise'   => true, // 是否添加杂点
             'use_img_bg'   => true, // 是否使用背景图片
         ],

         // 独立配置
         'sign' => [
             'char_preset' => '0123456789', // 预设字符集
             'length'     => 4, // 验证码位数
             'width'      => 100, // 图片宽
             'height'     => 36, // 图片高
             'font_size'   => 24, // 验证码字体大小(px)
             'use_img_bg'   => false, // 是否使用背景图片
         ],
     ];

```

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Every ~78 days

Total

5

Last Release

1705d ago

Major Versions

v1.0.1 → v2.0.02021-01-04

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/26112249?v=4)[未名](/maintainers/phpu)[@phpu](https://github.com/phpu)

---

Top Contributors

[![liujiawm](https://avatars.githubusercontent.com/u/6715852?v=4)](https://github.com/liujiawm "liujiawm (33 commits)")

---

Tags

base64captchapngthink-captchathinkcaptchathinkphpcaptchathinkphpthink-captchathinkcaptchaphpu

### Embed Badge

![Health badge](/badges/phpu-think-captcha/health.svg)

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

###  Alternatives

[liliuwei/thinkphp-jump

适用于thinkphp6.0+的跳转扩展

2876.7k1](/packages/liliuwei-thinkphp-jump)[isszz/rotate-captcha

Rotate image captcha

801.9k](/packages/isszz-rotate-captcha)[xiaodi/think-pullword

ThinkPHP 分词/抽词 扩展包

5612.5k](/packages/xiaodi-think-pullword)[ichynul/tpextmyadmin

thinkphp extension

141.6k](/packages/ichynul-tpextmyadmin)[xiaodi/think-pinyin

ThinkPHP 中文转拼音扩展包

344.8k](/packages/xiaodi-think-pinyin)

PHPackages © 2026

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