PHPackages                             diszo2009/multi-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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. diszo2009/multi-captcha

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

diszo2009/multi-captcha
=======================

Multiple(7) types of CAPTCHA in one package. Supports Gif captcha( Animated Gif captcha), Image Captcha( User has to type SOME OR ALL part of code displayed in the image), HoneyPot captcha(It simply adds an empty field asking users to leave it blank. Bots fill it up.), ASCII captcha(It displays the CAPTCHA text as ASCII Art. User has to type SOME OR ALL part of the code.), Math captcha( It asks user to solve simple mathematical expressions.), Recaptcha(Google Recaptcha) and NoCaptcha(Google ReCaptcha v2.0). This package also has captcha refresh feature.

v1.3.2(10y ago)019AGPL3.0PHPPHP &gt;=5.3.0

Since Jun 19Pushed 10y ago1 watchersCompare

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

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

multi-captcha
=============

[](#multi-captcha)

As the name says, this is one package to render them all! Multiple types of CAPTCHA in one package. Sometimes we just need to avoid spambots still want to keep the forms user-friendly and sometimes we need complete protection even if becomes a bit complex for users. MultiCaptcha helps you have uniform Captcha validation code over your projects.

Key Features
------------

[](#key-features)

1. 7 types of captcha supported with multitude of configuration options for each of them.
2. Shows refresh button (you need to provide refresh url).
3. Each Captcha challenge can be submitted only once.
4. Customizable error messages
5. You can customize the look and feel using *themeOptions* Or you can write your own theme/s.

Supported types of CAPTCHA
--------------------------

[](#supported-types-of-captcha)

Captcha TypeScreenshotDescriptionProtectionDifficulty for humansimage[![Image Captcha Screenshot](/examples/image-captcha.gif)](/examples/image-captcha.gif)Asks user to identify all or some characters from the jpg image. [Live demo](http://demo.techrevol.com/multicaptcha/examples/image-captcha.php)HighAveragegif[![Gif Captcha Screenshot](/examples/gif-captcha.gif)](/examples/gif-captcha.gif)Asks user to identify all or some characters from the animated image. [Live demo](http://demo.techrevol.com/multicaptcha/examples/gif-captcha.php)HighAverageascii[![Ascii Captcha Screenshot](/examples/ascii-captcha.gif)](/examples/ascii-captcha.gif)Asks user to identify all or some characters from code displayed in ASCII art. [Live demo](http://demo.techrevol.com/multicaptcha/examples/ascii-captcha.php)ModerateAveragemath[![Math Captcha Screenshot](/examples/math-captcha.gif)](/examples/math-captcha.gif)Asks user to solve simple mathematical expression. [Live demo](http://demo.techrevol.com/multicaptcha/examples/math-captcha.php)Below AverageEasyhoneypot[![Honeypot Captcha Screenshot](/examples/honeypot-captcha.gif)](/examples/honeypot-captcha.gif)Asks user to leave the captcha field blank. [Live demo](http://demo.techrevol.com/multicaptcha/examples/honeypot-captcha.php)LowVery Easyrecaptcha[![Recaptcha Screenshot](/examples/recaptcha-captcha.jpg)](/examples/recaptcha-captcha.jpg) *(image is resized)*Google ReCaptcha. Asks user to identify all characters displayed in the jpg image. [Live demo](http://demo.techrevol.com/multicaptcha/examples/recaptcha-captcha.php)HighAveragenocaptcha[![NoCaptcha Screenshot](/examples/nocaptcha-captcha.jpg)](/examples/nocaptcha-captcha.jpg) *(image is resized)*Google NoCaptcha(Recaptcha v2.0). [Live demo](http://demo.techrevol.com/multicaptcha/examples/nocaptcha-captcha.php)ModerateAverageInstallation:
-------------

[](#installation)

### Using Composer

[](#using-composer)

#### Command Line

[](#command-line)

You can install MultiCaptcha using Composer by doing

```
composer require sameer-shelavale/multi-captcha

```

#### composer.json

[](#composerjson)

Alternatively, you can add it directly in your composer.json file in require block

```
{
    "require": {
        "sameer-shelavale/multi-captcha": "1.3.*"
    }
}

```

and then run

```
composer update

```

### PHP Include

[](#php-include)

Or you can download the zip/rar archive and extract it and copy the /src folder to appropriate location in your project folder. And then include the captcha.php

Note: Make sure the cache directory is writable.

```
include_once( 'PATH-TO-MULTI-CAPTCHA-FOLDER/src/Captcha.php' );

```

Usage:
------

[](#usage)

### Initialize:

[](#initialize)

The minimal code required to initialize the captcha looks like:

```
$captcha = new \MultiCaptcha\Captcha([
    'secret'=>    "your-secret-key",
] );
```

The above code will initialize the captcha object to output "image" captcha which is default. Note: Its important to set your own secret key, as its used to encrypt and decrypt the captcha fields.

And more customized code looks like:

```
$captcha = new \MultiCaptcha\Captcha([
    'secret'=>    "your-secret-key",
    'life' => 2, //number of hours the generated captcha will be valid
    'customFieldName' => 'my_captcha', //this becomes the name of captcha answer field
    'options' =>  [
        'image' => [
            'maxCodeLength' => 8,
            'font'=>'../src/types/image/comic.ttf',
            'width'=>180
        ]
    ]
] );
```

Now, that we have basic knowledge of how to initialize it, lets look at the supported parameters in details,

#### Supported Parameters

[](#supported-parameters)

paramdescription*secret*Your secret code for encryption and decryption of the form. It is recommended that you use different codes for each different web form.*life*total number of hours the generated captcha will be valid. If you set it to 2, then after 2 hours the validate() function will return false even if you enter the correct code. Basically it means the user is expected to submit the form within these many hours after opening the form.*customFieldName*a custom name for the captcha answer field. If not provided it will use encrypted random name for the field. *Note: Recaptcha type does not honor this parameter.**options*field contains the array with type of captcha/s that can be rendered as keys and their configurations as value array. If we pass more than one captcha type with it's configuration, it will randomly display one type of captcha from the supplied types. We will see configuration details of each type in details in next section.*refreshUrl*(Optional) url from which we will GET the new captcha using AJAX. If not provided refresh button will not be displayed. Also note that this feature is useful mainly with image, gif, ascii and math captcha.*helpUrl*(Optional) url which will provide help related to the captcha type. This url will open in new tab/window.#### Options

[](#options)

Right now we can render 7 types of captcha namely *image*, *gif*, *ascii*, *math*, *honeypot*, *recaptcha* and *nocaptcha*. Now lets look in details at the supported configuration parameters for each of them.

##### Image Captcha

[](#image-captcha)

Configuration ParamDefault ValueRequiredDescription*minCodeLength*4OptionalMaximum length of code to be displayed in the image*maxCodeLength*8OptionalMaximum length of code to be displayed in the image*maxRequired*5OptionalMaximum number of characters it can ask the user to identify*minRequired*3OptionalMinimum number of characters it can ask the user to identify*noiseLevel*25OptionalNumber of background noisy characters to be added as noise*width*150OptionalWidth of the captcha image in pixels*height*40OptionalHeight of the captcha image in pixels*font*src/fonts/segoesc.ttfOptionalPath to the font file which will be used for creating the characters##### Gif Captcha(GIF Animated captcha)

[](#gif-captchagif-animated-captcha)

Configuration ParamDefault ValueRequiredDescription*totalFrames*60OptionalTotal number of frames to be produced. Please note having too many frames may overload server during heavy traffic*delay*5Optionaldelay between frames in Millisecond*minCodeLength*4OptionalMaximum length of code to be displayed in the image*maxCodeLength*8OptionalMaximum length of code to be displayed in the image*maxRequired*5OptionalMaximum number of characters it can ask the user to identify*minRequired*3OptionalMinimum number of characters it can ask the user to identify*noiseLevel*25OptionalNumber of background noisy characters to be added as noise*width*150OptionalWidth of the captcha image in pixels*height*40OptionalHeight of the captcha image in pixels*font*src/fonts/comic.ttfOptionalPath to the font file which will be used for creating the characters##### ASCII Captcha

[](#ascii-captcha)

Configuration ParamDefault ValueRequiredDescription*fonts*comic.ttfOptionalarray containing font name(without extension) as key and the size to be rendered in pixels as value. The figlet fonts vary in size when rendered so in order to control the height and width of the captcha we need to pass the font-size. For large fonts you can pass smaller value of font size.*fontPath*nullOptionalIf you want your own Figlet fonts you can specify path to the folder containing them here.*minCodeLength*4OptionalMaximum length of code to be displayed in the image*maxCodeLength*8OptionalMaximum length of code to be displayed in the image*maxRequired*5OptionalMaximum number of characters it can ask the user to identify*minRequired*3OptionalMinimum number of characters it can ask the user to identifyASCII font names: You can find the currently supported ASCII figlet fonts in src/types/ascii/fonts/ folder and use the name of the font without the .flf extension.

**Example of ASCII captcha configuration:**

```
$captcha = new \MultiCaptcha\Captcha([
    'secret'=>    "your-secret-key",
    'options' =>  [
        'ascii' => [
            'maxCodeLength' => 8,
            'fonts'=>array(
                'banner' => 4, //render with font size 4px or it becomes too big
                'doom' => 8, //render with font size 8px
                'small' =>'8' //render with font size 8px, "small" font is at src/types/ascii/fonts/small.flf
            )
        ]
    ]
] );
```

Note, the fonts parameter, it has the font name without extension as key. and the size in pixels as the value. Unless you provide a *fontPath* parameter, it will look in src/types/ascii/fonts/ folder for that font.

##### Math Captcha(Simple Mathematical expression)

[](#math-captchasimple-mathematical-expression)

Configuration ParamDefault ValueRequiredDescription*level*4OptionalNumber of variables(digits) in the mathematical expression*description*nullRequiredSome text asking the user to solve the mathematical expression.##### Honeypot Captcha

[](#honeypot-captcha)

Configuration ParamDefault ValueRequiredDescription*description*nullRequiredSome text asking the user to leave the captcha field blank(bots will try to fill it up and get caught)##### Recaptcha

[](#recaptcha)

Configuration ParamDefault ValueRequiredDescription*publicKey*nullRequiredYou Recaptcha Public key given to you by Google*privateKey*nullRequiredYou Recaptcha Public key given to you by GoogleNote: You can register and get your recaptcha keys at

##### Nocaptcha

[](#nocaptcha)

Configuration ParamDefault ValueRequiredDescription*siteKey*nullRequiredYou Recaptcha Site key given to you by Google*secretKey*nullRequiredYou Recaptcha Secret key given to you by Google*lang*enOptionallanguage code as on Note: You can register and get your recaptcha keys at##### You can generate random type of captcha from multiple configured types.

[](#you-can-generate-random-type-of-captcha-from-multiple-configured-types)

For example You can do:

```
$captcha = new \MultiCaptcha\Captcha([
    'secret'=>    "your-secret-key",
    'options' =>  [
        'math' => array(
            'description'=> "Answer following question if you are human",
            'level' => 4
        ),
        'image' => array(
            'maxCodeLength' => 8,
            'font'=>'../src/types/image/comic.ttf',
            'width'=>180
        ),
        'ascii' => array(
            'maxCodeLength' => 8,
            'fonts'=>array(
                'banner'=> 4,
                'doom'=> 8,
                'small'=>'8'
            )
        ),
        'gif' => array(
            'maxCodeLength' => 8,
            'font'=>'../src/types/image/comic.ttf',
            'width'=>180,
            'height'=>60,
            'totalFrames'=>50,
            'delay'=>20
        )
    ]
] );
```

And then it will generate a random type of captcha from the 4 types which are configured

### Render

[](#render)

You can use the following one liner to render the captcha

```
echo $captcha->render() ;
```

That will do it.(note that $captcha is the name of object you initialized)

### Refresh

[](#refresh)

To display the refresh button, its necessary to provide the refreshUrl. Then in script of that url you can do.

```
echo $captcha->refresh() ;
exit; //this is important to ensure no html is trailing the captcha
```

Note: make sure no html is displayed before or after the `captcha->refresh();`You can also render and refresh at same page, please refer to the gif, ascii, image and math captcha examples.

### Validate

[](#validate)

You can validate your form data simply by doing

```
if( $captcha->validate( $_POST ){
    //do further processing, validate individual form fields
}
```

Note: We need to pass all the submitted data to the validate function because the name of captcha field is encrypted &amp; random. If you specify the customFieldName parameter it will require that field and the challenge field for validation. E.g. if customFieldName = my\_captcha, then you need to pass an array

```
if( $captcha->validate( [ 'my_captcha'=>$_POST['my_captcha'], 'my_captcha_challenge'=>$_POST['my_captcha_challenge'] ] ){
    //do further processing, validate individual form fields
}
```

or

```
if( $captcha->validate( array_intersect_key($_POST, array_flip(['my_captcha', 'my_captcha_challenge']) ) ) ){
    //do further processing, validate individual form fields
}
```

### Themes/customization

[](#themescustomization)

MultiCaptcha ships with a default theme named DefaultTheme. This theme supports customization of its color/style through various parameters nested under *themeOptions*. e.g. you can change the background color to blue

```
$captcha = new \MultiCaptcha\Captcha([
    'secret'=>    "form1-secret-key",
    'options' =>  [
        'image' => array(
            'maxCodeLength' => 8,
            'font'=>'../src/types/image/comic.ttf',
            'width'=>180,
            'themeOptions' => [
                'containerStyle' => 'border:1px solid #0f702d; border-radius: 5px; padding: 5px; display: table; margin: 2px; background-color: #29713f; font-family: Helvetica; font-size: 14px; max-width: 180px;position:relative;',
                'fieldStyle' => 'background-color:#52785e; border:2px solid #fff; color:#fff; font-size:120%; font-weight:bold; border-radius:3px;width:144px;',
                'labelStyle' => 'font-size:80%; line-height:100%; color: #fff;',
            ]
        ),
        'ascii' => array(
            'maxCodeLength' => 8,
            'fonts'=>array(
                'banner'=> 4,
                'doom'=> 8,
                'small'=>'8'
            ),
            'themeOptions' => [
                'containerStyle' => 'border:1px solid #1e2a37; border-radius: 5px; padding: 10px; display: table; margin: 2px; background-color: #374c63; font-family: Helvetica; font-size: 14px; max-width: 180px;position:relative;',
                'fieldStyle' => 'background-color:#4d5d6f; border:2px solid #fff; color:#fff; font-size:120%; font-weight:bold; border-radius:3px;width:144px;',
                'labelStyle' => 'font-size:80%; line-height:100%; color: #fff;'
            ]
        ),
    ],
    'refreshUrl'=>'random.php?captcha=refresh',
    'helpUrl'=>'http://github.com/sameer-shelavale/multi-captcha',

] );

```

Note: each captcha type can have its own *theme* and *themeOptions*

#### themeOptions for DefaultTheme

[](#themeoptions-for-defaulttheme)

Configuration ParamDescriptionDefault Value*fieldClass*class for the input field*fieldStyle*css styles for the input fieldbackground-color:#f66a03; border:2px solid #fff; font-size:120%; font-weight:bold; border-radius:3px;width:144px;*containerStyle*css styles for the main container which contains all captcha elements (without the *style=* part and without enclosing quotes)border:3px solid #000; border-radius: 5px; padding: 10px; display: table; margin: 2px; background-color: #f69d03; font-family: Arial; font-size: 14px; max-width: 180px;position:relative*questionImageStyle*css styles for the image code(for *image* or *gif* types )border-radius:3px; margin-bottom:5px;*questionTextStyle*css styles for the question/challenge text(for *math* type)font-size:120%; font-weight:bold;background-color:#ccc; border-radius:3px; padding:4px;margin-bottom:2px;text-align:center;display:block;min-width:172px;*questionAsciiStyle*css styles for ASCII text(for the challenge text of *ascii* type)background-color:#ccc; border-radius:3px; padding:4px;margin-bottom:2px;text-align:center;display:block;min-width:172px;*questionContainerStyle*css styles for the container of the question/challengenone ;*labelStyle*css style for labelfont-size:80%; line-height:100%;*helpBtnClass*css class for the help buttobtn-help*helpBtnText*text to show on the help button?*refreshBtnClass*css class for the refresh buttonbtn-refresh*refreshBtnText*text to show up on the refresh button↺*extraHtml*extra css styles(with the enclosing style tag)&lt;style type="text/css"&gt; a.btn-refresh, a.btn-help{ background-color:#fff; text-decoration:none; color:#f66a03; padding:1px 2px; border-radius:2px; vertical-align:top; margin-left:2px; display:inline-block; width:12px; height:12px; text-align:center; line-height:100%; font-size:12px; } &lt;/style&gt;With the above themeOptions you will be able to change the look and feel of the default theme. However if you need to change the placements of the elements you will have to write your own theme by extending the DefaultTheme Please refer example/theming.php for working example of *themeOptions*.

#### Extending the DefaultTheme

[](#extending-the-defaulttheme)

1. The render() and refresh() functions are crucial for rendering the captcha, your theme must have it.
2. When you extend the DefaultTheme you can use that theme by setting the *theme*e.g.

```
$captcha = new \MultiCaptcha\Captcha([
    'secret'=>    "form1-secret-key",
    'options' =>  [
        'image' => array(
            'maxCodeLength' => 8,
            'font'=>'../src/types/image/comic.ttf',
            'width'=>180,
            'theme' => 'CustomTheme1'
        ),
        'ascii' => array(
            'maxCodeLength' => 8,
            'fonts'=>array(
                'banner'=> 4,
                'doom'=> 8,
                'small'=>'8'
            ),
            'theme' => 'CustomTheme2'
        ),
    ],
] );

```

Note: you can have your own *themeOptions* when you make your own theme. Also remember to update javascipt refresh function, it needs updating whenever you change the structure/layout.

### Cache

[](#cache)

Multicaptcha uses file cache to record the answered captcha and uses it to block brute-force attack using single captcha and multiple answers. It stores the unique id of captcha and expiration time in the record, and that record is kept till the captcha expires. It uses file cache to store these records. To avoid the cache becoming too big the records are dispersed over multiple files. The number of files to be used for caching is specified by a variable *$cacheSize*and the directory in which the files should be stored is specified by *$cacheDir*, you can pass both of these variables as params to the constructor. Default cache size is 10, but you can increase it for busy websites. Note: The cache directory MUST be writable if you are using the default file cache implementation.

Features under progress
-----------------------

[](#features-under-progress)

1. Multi-language support

Planned Features
----------------

[](#planned-features)

1. Custom background image for image and gif captcha

License
-------

[](#license)

AGPL3.0, Free for non-commercial use. Email me at  for other type of licensing.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 98.4% 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 ~6 days

Total

7

Last Release

3943d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/455507c46751486f4bd7a715d8278ab7ed8cee8ddf276f5a2eafc25b64828f12?d=identicon)[diszo2009](/maintainers/diszo2009)

---

Top Contributors

[![sameer-shelavale](https://avatars.githubusercontent.com/u/3716265?v=4)](https://github.com/sameer-shelavale "sameer-shelavale (63 commits)")[![diszo2009](https://avatars.githubusercontent.com/u/1811490?v=4)](https://github.com/diszo2009 "diszo2009 (1 commits)")

---

Tags

recaptchacaptchaHoneypotmath captchanocaptchamulti captchaimage captchagif captchaanimated captchaanimated gif captchaASCII captchahoneypot captchamathematical captchaGoogle ReCaptchaGoogle NoCaptcha

### Embed Badge

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

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

###  Alternatives

[google/recaptcha

Client library for reCAPTCHA, a free service that protects websites from spam and abuse.

3.6k89.1M222](/packages/google-recaptcha)[anhskohbo/no-captcha

No CAPTCHA reCAPTCHA For Laravel.

1.8k8.5M33](/packages/anhskohbo-no-captcha)[buzz/laravel-google-captcha

Google captcha for Laravel

2071.1M2](/packages/buzz-laravel-google-captcha)[albertcht/invisible-recaptcha

Invisible reCAPTCHA For Laravel.

6031.6M6](/packages/albertcht-invisible-recaptcha)[josiasmontag/laravel-recaptchav3

Recaptcha V3 for Laravel package

2641.6M2](/packages/josiasmontag-laravel-recaptchav3)[arcanedev/no-captcha

No CAPTCHA (new Google reCAPTCHA) with Laravel support

370730.4k6](/packages/arcanedev-no-captcha)

PHPackages © 2026

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