2017 © Pedro Peláez
 

cakephp-plugin cakephp3-captcha

CakePHP 3.x - reCAPTCHA plugin

image

ivanamat/cakephp3-captcha

CakePHP 3.x - reCAPTCHA plugin

  • Monday, August 29, 2016
  • by ivanamat
  • Repository
  • 2 Watchers
  • 6 Stars
  • 2,105 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 7 % Grown

The README.md

CakePHP 4.5.x - reCAPTCHA

Installation

Composer

You can install this plugin into your CakePHP application using composer., (*1)

The recommended way to install composer packages is:, (*2)

composer require ivanamat/cakephp-captcha

Git submodule

git submodule add git@github.com:ivanamat/cakephp-captcha.git plugins/Captcha
git submodule init
git submodule update

Getting started

Get reCAPTCHA secret at https://www.google.com/recaptcha, (*3)

Configure

Set the secret in your config/bootstrap.php file., (*4)

    Configure::write('Captcha.secret','MY_SECRET_KEY');

Load Component

Load component in the initialize() function, (*5)

    class MyController extends AppController {

        public function initialize() {
            parent::initialize();

            $this->loadComponent('Captcha.Captcha');
        }

    }

...or load the component in the array of components., (*6)

    class MyController extends AppController {

        public $components = [
            'Captcha' => [
                'className' => 'Captcha.Captcha'
            ]
        ];

    }

Easy to use

Controller

    # MyController

    $ip = getenv('REMOTE_ADDR');
    $gRecaptchaResponse = $this->request->data['g-recaptcha-response'];

    $captcha = $this->Captcha->check($ip,$gRecaptchaResponse);

    if($captcha->errorCodes == null) {
        // Success
    } else {
        // Fail! Maybe a bot?
    }

HTML

Paste this snippet before the closing tag </head> in the HTML template, (*7)

    <script src='https://www.google.com/recaptcha/api.js'></script>

Paste this snippet at the end of the <form> where you want the reCAPTCHA widget to appear. Replace YOUR-SITEKEY with your own site key., (*8)

    <div class="g-recaptcha" data-sitekey="YOUR-SITEKEY"></div>

About CakePHP 4.x - reCAPTCHA

CakePHP 4.x - Captcha uses the reCAPTCHA third-party library.
You can download reCAPTCHA from official website: [https://github.com/google/recaptcha), (*9)

Google reCAPTCHA, (*10)

Contributors

Iván Amat on GitHub and www.ivanamat.es
BusaniPrepaid on GitHub, (*11)

The Versions

29/08 2016

dev-master

9999999-dev https://github.com/ivanamat/cakephp3-captcha

CakePHP 3.x - reCAPTCHA plugin

  Sources   Download

MIT

The Requires

 

plugin cakephp captcha google recaptcha cakephp3 cake3

29/08 2016

1.0

1.0.0.0 https://github.com/ivanamat/cakephp3-captcha

CakePHP 3.x - reCAPTCHA plugin

  Sources   Download

MIT

The Requires

 

plugin cakephp captcha google recaptcha cakephp3 cake3