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

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

bugcat/captcha
==============

PHP captcha with Chinese

v1.0.0(7y ago)7251MITPHPPHP &gt;=7.0

Since Mar 9Pushed 6y agoCompare

[ Source](https://github.com/bugcat/captcha)[ Packagist](https://packagist.org/packages/bugcat/captcha)[ RSS](/packages/bugcat-captcha/feed)WikiDiscussions master Synced 3d ago

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

Captcha with Chinese
====================

[](#captcha-with-chinese)

Installation
------------

[](#installation)

The Captcha Service Provider can be installed via [Composer](http://getcomposer.org) by requiring the `bugcat/captcha` package and setting the `minimum-stability` to `dev` in your project's `composer.json`.

```
{
    "require": {
        "bugcat/captcha": "~0.1"
    },
    "minimum-stability": "dev"
}
```

or

Require this package with composer:

```
composer require bugcat/captcha

```

Update your packages with `composer update` or install with `composer install`.

In Windows, you'll need to include the GD2 DLL `php_gd2.dll` in php.ini. And you also need include `php_fileinfo.dll` and `php_mbstring.dll` to fit the requirements of `bugcat/captcha`'s dependencies.

Usage
-----

[](#usage)

To use the Captcha Service Provider, you need to store the captcha characters and verify the correctness of the user's input. This captcha package is only responsible for generating characters and drawing captcha pictures.

Use it first.

```
    use Bugcat\Captcha\Captcha;
```

Load it then.

```
    $captcha = new Captcha();
```

Generate a new captcha using custom configuration, get the captcha codes, store it.

```
    $config = []; //custom configuration
    $codes = $captcha->gnrt($config);
    $_SESSION['captcha'] = $codes;
```

Output the image to the user

```
    $captcha->img();
```

Last, verify user input

```
    if ( $_POST['captcha'] == $_SESSION['captcha'] ) {
        //do something.
    } else {
        //do something.
    }
```

Configuration
-------------

[](#configuration)

There is a simple example for configuration in the captcha package, you can see it like this.

```
    $captcha = new Captcha();
    var_dump($captcha::CFG_EXP);
```

This is the full description.

```
    $config = [
        //Whether need a border, 1 is need and 0 is not, default 1.
        'border'   => '1|0',

        //The verification code length, 1 at least, default 4.
        'charnum'  => '4',

        //The fontsize of captcha,  using px, 8 at least, default 16.
        'fontsize' => '16',

        //The code direction, 0 is horizontal and  1 is vertical, default 0.
        'codedir'  => '1|0',

        //The font of code, use existing list or custom, default simhei.
        //This package provides these fonts: simhei, ABeeZee_regular, Asap_700, Khand_500, Open_Sans_regular, Roboto_regular, Ubuntu_regular, ygyxsziti2.0 .
        //If use custom, it needs the full and usable path.
        'font'     => 'simhei|Roboto_regular|/var/www/html/test/fonts/custom.ttf',

        //The character pool for captcha, use existing list or custom, default CHS.
        //This package provides these characters:
        //  CHS : Chinese Simplified
        //  CHT : Chinese Traditional
        //  ENG : 2346789ABCDEFGHJMNPQRTUXYZ
        'text'     => 'CHS|CHT|ENG|custom string allow spaces because it will be ignored',
    ];
```

Example Usage
-------------

[](#example-usage)

```
use Bugcat\Captcha\Captcha;

class Auth
{
    private $captcha;

    public function __construct()
    {
        $this->captcha = new Captcha();
    }

    public function vcode()
    {
        $config = ['charnum' => 2, 'text' => 'CHT'];
        $codes = $this->captcha->gnrt($config);
        $_SESSION['captcha'] = $codes;

        $this->captcha->img();
    }

    public function register()
    {
        if ( $_POST['CSRF'] ) {
            if ( !$this->verify() ) {
                die( 'the verification code is error.' );
            }
            //do something.
        }
        //do something.
    }

    private function verify()
    {
        if ( empty($_POST['captcha']) || empty($_SESSION['captcha']) ) {
            return false;
        }
        if ( $_POST['captcha'] == $_SESSION['captcha'] ) {
            return true;
        } else {
            retrun false;
        }
    }

}
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

Total

3

Last Release

2623d ago

Major Versions

0.1 → v1.0.02019-03-10

### Community

Maintainers

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

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

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