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

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

sunmking/think-captcha
======================

captcha package for thinkphp

120PHP

Since Aug 23Pushed 2y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

think-captcha
=============

[](#think-captcha)

thinkphp6 验证码类库

> 基于官方修改 支持 redis、file、memcached、memcache、wincache 需要在 config/cache.php 里添加相应的配置

安装
--

[](#安装)

> composer require sunmking/think-captcha

使用
--

[](#使用)

### 在控制器中输出验证码

[](#在控制器中输出验证码)

在控制器的操作方法中使用

```
public function captcha($id = '')
{
	return captcha($id);
}

```

然后注册对应的路由来输出验证码

### 模板里输出验证码

[](#模板里输出验证码)

无需在路由文件里注册路由规则，安装完成后会自动注册 2 个验证码路由规则。

```
\think\facade\Route::get('captcha/apis/[:config]', "\\Sunmking\\Captcha\\CaptchaController@index");
\think\facade\Route::get('captcha/[:config]', "\\Sunmking\\Captcha\\CaptchaController@index");

```

可以执行以下命令查看

```
 php think route:list

```

然后就可以在模板文件中使用

```
{:captcha_img()}

```

或者

```

```

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

### 控制器里验证

[](#控制器里验证)

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

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

```

或者手动验证

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

```

前后端分离使用
-------

[](#前后端分离使用)

### 配置

[](#配置)

1、需要在 config/cache.php 里添加相应的配置 2、需要在 config/captcha.php 里添加相应的驱动

```
// session 默认
//redis、file、memcached、memcache、wincache
'driver' => 'session'

```

### 获取

[](#获取)

请求以下接口获取 base64 图片和 uuid

```
\think\facade\Route::get('captcha/apis/[:config]', "\\Sunmking\\Captcha\\CaptchaController@index");

```

### 验证

[](#验证)

if(!captcha\_check($captcha,$uuid)){ //验证失败 };

> 如果驱动为 session uuid也可以不传

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity21

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/c9ecc98eec8f6e243c91d53019ffa4d86dab5da58a89d3d23d1523ebe4fec5ea?d=identicon)[sunmking](/maintainers/sunmking)

### Embed Badge

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

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

###  Alternatives

[aternos/thanos

Simple library to detect and remove unused chunks from a Minecraft world.

263586.9k](/packages/aternos-thanos)[kossa/algerian-cities

A Laravel package to create/load wilayas and communes of Algeria

847.9k](/packages/kossa-algerian-cities)[iconify/json-tools

Functions for manipulating Iconify JSON SVG collections.

1537.1k6](/packages/iconify-json-tools)[luilliarcec/laravel-username-generator

Laravel Username Generator is a package that allows the versatile generation of user names, has a simple integration with Laravel.

1011.8k](/packages/luilliarcec-laravel-username-generator)

PHPackages © 2026

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