PHPackages                             cakephp-fr/recaptcha - 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. cakephp-fr/recaptcha

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

cakephp-fr/recaptcha
====================

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

2.0.0(6y ago)1419.5k↓50%8[7 issues](https://github.com/cakephp-fr/recaptcha/issues)[1 PRs](https://github.com/cakephp-fr/recaptcha/pulls)MITPHPPHP &gt;=7.2

Since Dec 15Pushed 5y ago9 watchersCompare

[ Source](https://github.com/cakephp-fr/recaptcha)[ Packagist](https://packagist.org/packages/cakephp-fr/recaptcha)[ Docs](https://github.com/cakephp-fr/recaptcha)[ RSS](/packages/cakephp-fr-recaptcha/feed)WikiDiscussions master Synced yesterday

READMEChangelog (7)Dependencies (3)Versions (17)Used By (0)

Google reCAPTCHA for CakePHP 3
==============================

[](#google-recaptcha-for-cakephp-3)

[![Build Status](https://camo.githubusercontent.com/67b0b01e089c90f80769ca426e3e793da445e2f3ceae320e8c2d67dc9e6818de/68747470733a2f2f6170692e7472617669732d63692e6f72672f63616b657068702d66722f7265636170746368612e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/cakephp-fr/recaptcha)[![Latest Stable Version](https://camo.githubusercontent.com/c144295ab19682882a68a7e4e72ad9752ed4724f73b3bec27aea5ddcae519386/68747470733a2f2f706f7365722e707567782e6f72672f63616b657068702d66722f7265636170746368612f762f737461626c652e706e67)](https://packagist.org/packages/cakephp-fr/recaptcha)[![Minimum PHP Version](https://camo.githubusercontent.com/b8feeff753e7c6ff51ffd26c612be3c4f292513e413cd0c8884e665ff51dd798/687474703a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230352e342d3838393242462e737667)](https://php.net/)[![License](https://camo.githubusercontent.com/f7915a7e81a86457df8c05426c7b072769f84ed026f4b2400e74077dbafa7dbd/68747470733a2f2f706f7365722e707567782e6f72672f63616b657068702d66722f7265636170746368612f6c6963656e73652e706e67)](https://packagist.org/packages/cakephp-fr/recaptcha)[![Total Downloads](https://camo.githubusercontent.com/ea92bc914290df18dbd561b1d2548bba62fbdf682a0ff1e26e496a80d0c13382/68747470733a2f2f706f7365722e707567782e6f72672f63616b657068702d66722f7265636170746368612f642f746f74616c2e706e67)](https://packagist.org/packages/cakephp-fr/recaptcha)

Be careful version 1.0 is for CakePHP 3.6 minimum. For a previous CakePHP version please use the 0.4.2 version.

Plugin's Objective
------------------

[](#plugins-objective)

This plugin adds functionalities to use the new reCAPTCHA API version 2.0 in CakePHP projects.

This plugin is still under development... For now, multiple widgets on a single page is not available.

Requirements
------------

[](#requirements)

- PHP &gt;= 5.4.16
- [CakePHP 3.x](http://book.cakephp.org/3.0/en/index.html)
- Server under `localhost` name. Be aware that the widgets will not be displayed if you have a vhost named local.dev/dev/ for instance.

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

[](#installation)

*\[Using [Composer](http://getcomposer.org/)\]*

Add the plugin to your project's `composer.json` - something like this:

```
composer require cakephp-fr/recaptcha:~1.0
```

You then need to load the plugin, by running:

```
bin/cake plugin load -rb Recaptcha
```

You can check that this command has created the line `Plugin::load('Recaptcha', ['routes' => true, 'bootstrap' => true]);` at the bottom of your `config/boostrap.php` file.

The `'routes' => true` should be deleted in production. It's only useful if you want to see the demo.

Usage of plugin
---------------

[](#usage-of-plugin)

### 1. Go to Google reCAPTCHA site

[](#1-go-to-google-recaptcha-site)

Go [here](https://www.google.com/recaptcha/intro/index.html) to create a pair of keys for your website.

### 2. Configure the plugin

[](#2-configure-the-plugin)

The Easiest way is to add the recaptcha config to the `config/app.php`, something like:

```
return [

    .... (other configs before)

    'Recaptcha' => [
        // Register API keys at https://www.google.com/recaptcha/admin
        'sitekey' => 'your-sitekey',
        'secret' => 'your-secret',
        // reCAPTCHA supported 40+ languages listed
        // here: https://developers.google.com/recaptcha/docs/language
        'lang' => 'en',
        // either light or dark
        'theme' => 'light',
        // either image or audio
        'type' => 'image',
        // either normal or compact
        'size' => 'normal'
    ]
]
```

Make sure that `/config/app.php` file is in `.gitignore`. The secret key must stay secret.

If you don't have a key and a secret, an exception will be raised.

### 3. Then add the component in your controller where you need the reCAPTCHA.

[](#3-then-add-the-component-in-your-controller-where-you-need-the-recaptcha)

For example:

```
public function initialize() {
    parent::initialize();
    if ($this->request->getParam('action') === 'contact') {
        $this->loadComponent('Recaptcha.Recaptcha');
    }
}
```

```
public function contact() {
    if ($this->request->is('post')) {
        if ($this->Recaptcha->verify()) {
            // Here you can validate your data
            if (!empty($this->request->getData())) {
                $this->Flash->success(__('We will get back to you soon.'));
                return $this->redirect($this->referer());
            } else {
                $this->Flash->error(__('There was a problem submitting your form.'));
            }
        } else {
            // You can debug developers errors with
            // debug($this->Recaptcha->errors());
            $this->Flash->error(__('Please check your Recaptcha Box.'));
        }
    }
}
```

### 4. Finally add `` in your view template inside the form.

[](#4-finally-add--this-recaptcha-display--in-your-view-template-inside-the-form)

**No need** to add the helper: it will be added with the component.

For example:

```
