PHPackages                             inimist/cakephp-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. [Security](/categories/security)
4. /
5. inimist/cakephp-captcha

ActiveCakephp-plugin[Security](/categories/security)

inimist/cakephp-captcha
=======================

CakePHP Captcha Plugin, Image, Math and Google Recaptcha Support

1.3(6y ago)354241MITPHPPHP ^5.6|^7.0

Since Oct 21Pushed 4y ago2 watchersCompare

[ Source](https://github.com/inimist/cakephp3-captcha)[ Packagist](https://packagist.org/packages/inimist/cakephp-captcha)[ Docs](https://github.com/inimist/cakephp3-captcha)[ RSS](/packages/inimist-cakephp-captcha/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (4)Dependencies (1)Versions (4)Used By (1)

CakePHP Captcha Plugin
======================

[](#cakephp-captcha-plugin)

**Bot Detect using Image captcha, Math captcha and Google-recaptcha for CakePHP 3**

Why to use this plugin?
-----------------------

[](#why-to-use-this-plugin)

- To display Google Recaptcha / Image Captcha / Math Challenge for web forms

This CakePHP Captcha plugin requires CakePHP 3.6+.

Quick Features
--------------

[](#quick-features)

- No Custom Code required.
- Quick install. Just add 3 lines, on each in Controller, Model and View.
- Works as Model Validation.
- Multiple Captchas on single page.
- Multiple Demo available.
- Demo available as CakePHP Plugin.

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

[](#installation)

`composer require inimist/cakephp-captcha`

and

`bin/cake plugin load Captcha -b -r`

Implementation
--------------

[](#implementation)

1. Load **Captcha** plugin.

    If you ran `bin/cake plugin load Captcha -b -r` above skip this step.

    Place `Plugin::load('Captcha');` in your application's **Application.php** or **bootstrap.php** file.
2. Load **Capthca component**

    Place `$this->loadComponent('Captcha.Captcha');` in your controllerr's **initialize** function

    OR

    Load Captcha component on the fly, in the particular controller **action** function. For example in the signup() action:

    `$this->loadComponent('Captcha.Captcha'); //or load on the fly!`$
3. Add Behavior to your Model/Table

    Place `$this->addBehavior('Captcha.Captcha', ['field'=>''])` in your **Model** (Table class) Note: If you use Google Recaptcha add "secret" option with its value which you get from Google. Also, add Google site key in the view file.
4. Create an input field in your view's **form** as:

    `echo $this->Captcha->create('', $options);`
5. In your controller in which your form data is processed, place (required with image and math catpcha):

    `$this->Users->setCaptcha('', $this->Captcha->getCode(''));`

    just before patching entity. For example:

    ```
    $this->Users->setCaptcha('securitycode', $this->Captcha->getCode('securitycode'));
    $user = $this->Users->patchEntity($user, $this->request->data);

    ```

A fully working demo can be found [here](https://captcha.inimisttech.com). You can install a fully working demo as a plugin from [here](https://github.com/inimist/cakephp-captcha-demo).

Settings
--------

[](#settings)

The best place for settings is your\_apps/config/app.php file. Create a new key named "Captcha" and specify settings there.

```
'Captcha' => [
    'type' => 'recaptcha',
    'sitekey' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    //'clabel' => 'Enter code',
    //'reload_txt' => 'Reload??'
]

```

More examples
-------------

[](#more-examples)

### Options:

[](#options)

```
$options['width']=150;
$options['height']=50;
$options['theme']='default';
echo $this->Captcha->create('captcha_input_field_name', $options);

```

### Multiple Captchas on same page:

[](#multiple-captchas-on-same-page)

```
//form 1
$options1['width']=150;
$options1['height']=50;
echo $this->Captcha->create('captcha_input_field_name1', $options1);

//form 2, A math captcha, anywhere on the page
$options2['type']='math';
echo $this->Captcha->create('captcha_input_field_name2', $custom2);

```

**Options for view template. Ex: `$this->Captcha->create('field_name', $options)`:**

- *field*: field name (Optional. Default "captcha")
- *type*: recaptcha/image/math (Optional: Default "image")
- *width*: width of image captcha (Optional. Applies to type "image" only)
- *height*: height of image captcha (Optional. Applies to type "image" only)
- *theme*: default/random image captcha color pattern (Optional. Applies to type "image" only ; default "default")
- *length*: number of characters in image captcha (Optional. Applies to type "image" only)
- *angle*: angle of rotation for characters in image captcha (Optional. Applies to type "image" only)
- *fontAdjustment*: Font size for Image Captcha (Optional. Applies to type "image" only)
- *reload\_txt*: Reload Captcha Text (Optional)
- *clabel*: Label for Image Captcha field (Optional)
- *mlabel*: Label for Math Captcha field (Optional)
- *sitekey*: Googel Recaptcha Sitekey (Required. Applies to type "recatpcha" only)

(All above options can also be set from controller. Ex: `$this->loadComponent('Captcha.Captcha', $options)`)

\*\*Options for model. Ex: $this-&gt;addBehavior('Captcha.Captcha', $options);

- *field*: field name (optional: default "captcha")
- *secret*: Googel Recaptcha Secret (required for type "recatpcha")

Known Issues:
-------------

[](#known-issues)

1. **Headers already sent** issue. The component uses php's `header()` function to send or generate captcha image as raw HTML output. Make sure there is no output generated before the create() function in your component. It is common error to have spaces, tags or empty space in your files which would cause rending no image in the captcha.
2. **GD library** and True Type Font (**TTF**) support extensions are enabled in PHP.
3. This captcha script uses three random font faces, **anonymous**, **droidsans** and **ubuntu** to generate fonts in the captcha images. These font faces are placed in the **captcha/src/Lib/Fonts** of this download. I have seen that, sometimes, these font files get corrupted during downloads. If you see font not found error in your error logs and captcha are failed to generate, try downloading these font faces from their respective sources and replace them in the mentioned folder. You can also use different font families by placing them Fonts folder and referencing them in the **CaptchaComponent.php** component file.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.1% 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 ~12 days

Total

3

Last Release

2373d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/447618?v=4)[Arvind Kumar](/maintainers/inimist)[@inimist](https://github.com/inimist)

---

Top Contributors

[![inimist](https://avatars.githubusercontent.com/u/447618?v=4)](https://github.com/inimist "inimist (74 commits)")[![saeideng](https://avatars.githubusercontent.com/u/8215801?v=4)](https://github.com/saeideng "saeideng (2 commits)")[![karmicdice](https://avatars.githubusercontent.com/u/3824371?v=4)](https://github.com/karmicdice "karmicdice (1 commits)")

---

Tags

cakephpcakephp-plugincakephp3xcaptchagoogle-recaptchaimage-captchamathmath-captchasecurityspam-protectionpluginsecuritycakephprecaptchacaptcha

### Embed Badge

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

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

###  Alternatives

[cakephp-fr/recaptcha

To easily use Google Recaptcha (free CAPTCHA service that protect websites from spam and abuse) in CakePHP projects

1419.3k](/packages/cakephp-fr-recaptcha)[cake17/cakephp-recaptcha

\[DEPRECIATED\] Please use https://github.com/cakephp-fr/recaptcha/

1211.0k1](/packages/cake17-cakephp-recaptcha)

PHPackages © 2026

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