PHPackages                             zxjdsb/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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. zxjdsb/captcha

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

zxjdsb/captcha
==============

一个简单的laravel5图形验证码扩展包

6(6y ago)036MITPHPPHP &gt;=5.5

Since Apr 25Pushed 6y agoCompare

[ Source](https://github.com/zxj95121/captcha)[ Packagist](https://packagist.org/packages/zxjdsb/captcha)[ RSS](/packages/zxjdsb-captcha/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (18)Used By (0)

[![Build Status](https://camo.githubusercontent.com/1fde112dd9030b6cefa927a2ad84ea7c3e69e54094026f7e0a58e39806fe96d4/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f766963656e732f636170746368612f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/vicens/captcha/build-status/master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/df90eba9d49e6eb4bb654aea0bd118afd35cec0b90f57d493678c54038ca6f47/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f766963656e732f636170746368612f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/vicens/captcha/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/f8951acd8bfe0093c576182d9e53d2013d95a469db400724fd521311aeab1a98/68747470733a2f2f706f7365722e707567782e6f72672f766963656e732f636170746368612f762f737461626c65)](https://packagist.org/packages/vicens/captcha)[![Total Downloads](https://camo.githubusercontent.com/c22738741c9312cf53ae691596503bd2662bf3115824548a85d42d40d707ceb8/68747470733a2f2f706f7365722e707567782e6f72672f766963656e732f636170746368612f646f776e6c6f616473)](https://packagist.org/packages/vicens/captcha)[![License](https://camo.githubusercontent.com/461a52c2f58c5991b8fb1759a859cd2cf49a1dacda23141f783c2d2c766f06ad/68747470733a2f2f706f7365722e707567782e6f72672f766963656e732f636170746368612f6c6963656e7365)](https://packagist.org/packages/vicens/captcha)

简介
--

[](#简介)

一个简单的laravel5图形验证码扩展包（zxj95121已fork并做验证码存储到redis的修改，因为Session不支持前后端分离）

环境要求
----

[](#环境要求)

1. PHP &gt;= 5.5
2. php-gd
3. [illuminate\\support](https://github.com/illuminate/support) ^5.1
4. [symfony/http-foundation](https://github.com/symfony/http-foundation) &gt;= 2.0

安装
--

[](#安装)

### 使用composer安装扩展包

[](#使用composer安装扩展包)

先通过`composer`安装扩展包到项目中

```
composer require vicens/captcha
```

### 注册服务提供者和别名(Laravel5.5无需手动注册)

[](#注册服务提供者和别名laravel55无需手动注册)

在`config/app.php` 配置文件的`providers`数组中，注册服务提供者：

```
'providers' => [
    // Other service providers...
    \Vicens\Captcha\Providers\CaptchaServiceProvider::class
]
```

如果你使用`Captcha`别名的话，在`aliases`数组中注册别名：

```
'aliases' => [
    // Other facades...
    'Captcha' => \Vicens\Captcha\Facades\Captcha::class
]
```

配置
--

[](#配置)

如果你想使用自己的配置,你可以执行以下命令发布配置文件`config/captcha.php`：

```
php artisan vendor:publish --provider=\Vicens\Captcha\Providers\CaptchaServiceProvider
```

```
return array(
    /**
     * 调试模式(不验证验证码的正确性), 设置为null时, 取值为app.debug
     *
     * @var bool|null
     */
    'debug' => env('CAPTCHA_DEBUG', false),
    /**
     * 验证码的访问路径
     *
     * @var string
     */
    'route' => '/captcha',
    /**
     * 路由名
     *
     * @var string
     */
    'name' => 'captcha',
    /**
     * 中间件名，必须开启session
     *
     * @var string
     */
    'middleware' => 'web',
    /**
     * 默认验证码长度
     *
     * @var int
     */
    'length' => 4,
    /**
     * 验证码字符集
     *
     * @var string
     */
    'charset' => 'abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789',
    /**
     * 是否开启严格模式(区分大小写)
     *
     * @var bool
     */
    'strict' => false,
    /**
     * 默认验证码宽度
     *
     * @var int
     */
    'width' => 150,
    /**
     * 默认验证码高度
     *
     * @var int
     */
    'height' => 40,
    /**
     * 指定文字颜色
     *
     * @var string
     */
    'textColor' => null,
    /**
     * 文字字体文件
     *
     * @var string
     */
    'textFont' => null,
    /**
     * 指定图片背景色
     *
     * @var string
     */
    'backgroundColor' => null,
    /**
     * 开启失真模式
     *
     * @var bool
     */
    'distortion' => true,
    /**
     * 最大前景线条数
     *
     * @var int
     */
    'maxFrontLines' => null,
    /**
     * 最大背景线条数
     *
     * @val int
     */
    'maxBehindLines' => null,
    /**
     * 文字最大角度
     *
     * @var int
     */
    'maxAngle' => 8,
    /**
     * 文字最大偏移量
     *
     * @var int
     */
    'maxOffset' => 5
);
```

基本用法
----

[](#基本用法)

#### 生成验证码图片实例

[](#生成验证码图片实例)

```
use \Vicens\Captcha\Facades\Captcha;

$image = Captcha::make();
$image = Captcha::setConfig($config)->make();
$image = Captcha::width(100)->height(40)->make();
```

#### 图片实例用法

[](#图片实例用法)

直接返回`Response`对象：

```
$image->response();
```

直接输出给浏览器：

```
$image->output();
```

输出`img`标签：

```
Captcha::html($width, $height);
```

返回`base64`编码：

```
$image->getBase64();
```

返回`base64`Url地址：

```
$image->getDataUrl();
```

返回图片二进制内容：

```
$image->getContent();
```

保存图片到服务器：

```
$image->save($filename);
```

#### 验证和测试

[](#验证和测试)

仅测试验证码的正确性：

```
Captcha::test($input);
```

检测验证码的正确性，并且从缓存中删除验证码：

```
Captcha::check($input);
```

#### 使用中间件

[](#使用中间件)

在路由上使用：

```
Route::post('login','LoginController@login')->middleware(\Vicens\Captcha\Middleware\CaptchaMiddleware::class);
```

在控制器中使用：

```
public function __constructor(){
   $this->middleware(\Vicens\Captcha\Middleware\CaptchaMiddleware::class)->only(['login', 'register']);
}
```

#### 使用表单验证器

[](#使用表单验证器)

在控制器中使用：

```
$this->validation([
   'code' => 'captcha'
]);
```

在`Request`中使用：

```
public function rules()
{
   return [
       'code' => 'captcha'
   ];
}
```

#### 外观方法

[](#外观方法)

返回验证码URL：

```
Captcha::url();
Captcha::src();
```

返回验证码`img`标签：

```
Captcha::image();
```

返回可点击切换验证码的`img`标签：

```
Captcha::clickableImage();
```

开源协议
----

[](#开源协议)

[MIT license](http://opensource.org/licenses/MIT).

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity67

Established project with proven stability

 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 ~74 days

Recently: every ~0 days

Total

17

Last Release

2480d ago

Major Versions

v1.0 → v2.02017-04-08

v2.0.1 → v3.0.12017-12-10

v3.1.1 → v4.0.02018-01-21

v4.1.6 → v5.0.12019-07-26

PHP version history (2 changes)v1.0PHP &gt;=5.4

v2.0PHP &gt;=5.5

### Community

Maintainers

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

---

Top Contributors

[![simonetoo](https://avatars.githubusercontent.com/u/13295498?v=4)](https://github.com/simonetoo "simonetoo (7 commits)")

---

Tags

laravelcaptchalaravel5verification Code

### Embed Badge

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

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

###  Alternatives

[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[schuppo/password-strength

This package provides a validator for ensuring strong passwords in Laravel 4 applications.

1432.7M1](/packages/schuppo-password-strength)[elic-dev/laravel-math-captcha

A simple math captcha for Laravel form validation.

1156.7k](/packages/elic-dev-laravel-math-captcha)[bllim/laravalid

This package makes validation rules defined in laravel work client-side by converting to html/js plugins such as jquery validation. It also allows to use laravel validation messages so you can show same messages for both sides.

5915.2k](/packages/bllim-laravalid)[mohsen/captcha

A simple captcha for laravel 4

125.2k](/packages/mohsen-captcha)

PHPackages © 2026

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