2017 © Pedro Peláez
 

library recaptcha

Middleware to use Google reCAPTCHA for spam prevention

image

middlewares/recaptcha

Middleware to use Google reCAPTCHA for spam prevention

  • Saturday, January 27, 2018
  • by oscarotero
  • Repository
  • 1 Watchers
  • 3 Stars
  • 20 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 5 % Grown

The README.md

middlewares/recaptcha

Latest Version on Packagist ![Software License][ico-license] Testing ![Total Downloads][ico-downloads], (*1)

Middleware to use google/recaptcha library for spam prevention. Returns a 403 response if the request is not valid. More info about Google reCAPTCHA., (*2)

Requirements

Installation

This package is installable and autoloadable via Composer as middlewares/recaptcha., (*3)

composer require middlewares/recaptcha

Example

$dispatcher = new Dispatcher([
    new Middlewares\Recaptcha($secretKey),

    //in your view
    function () {
        echo '<div class="g-recaptcha" data-sitekey="XXX"></div>';
        echo '<script type="text/javascript" src="https://www.google.com/recaptcha/api.js"></script>';
    }
]);

$response = $dispatcher->dispatch(new ServerRequest());

Usage

You need a secret API key for your app. You can register it at https://www.google.com/recaptcha/admin, (*4)

$secretKey = 'Your-Secret-Key';

$recaptcha = new Middlewares\Recaptcha($secretKey);

Optionally, you can provide a Psr\Http\Message\ResponseFactoryInterface as the second argument to create the error responses (403). If it's not defined, Middleware\Utils\Factory will be used to detect it automatically., (*5)

$responseFactory = new MyOwnResponseFactory();

$recaptcha = new Middlewares\Recaptcha($secretKey, $responseFactory);

ipAttribute

By default uses the REMOTE_ADDR server parameter to get the client ip. This option allows to use a request attribute. Useful to combine with a ip detection middleware, for example client-ip:, (*6)

$dispatcher = new Dispatcher([
    //detect the client ip and save it in "ip" attribute
    (new Middlewares\ClientIP())->attribute('ip'),

    //use that attribute
    (new Middlewares\Recaptcha($secretKey))->ipAttribute('ip')
]);

Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details., (*7)

The MIT License (MIT). Please see LICENSE for more information., (*8)

The Versions

27/01 2018

dev-master

9999999-dev https://github.com/middlewares/recaptcha

Middleware to use Google reCAPTCHA for spam prevention

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 security server http captcha google recaptcha psr-15

27/01 2018

v1.0.0

1.0.0.0 https://github.com/middlewares/recaptcha

Middleware to use Google reCAPTCHA for spam prevention

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 security server http captcha google recaptcha psr-15

13/11 2017

v0.5.0

0.5.0.0 https://github.com/middlewares/recaptcha

Middleware to use Google reCAPTCHA for spam prevention

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 security server http captcha google recaptcha psr-15

21/09 2017

v0.4.0

0.4.0.0 https://github.com/middlewares/recaptcha

Middleware to use Google reCAPTCHA for spam prevention

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 security server http captcha google recaptcha psr-15

26/12 2016

v0.3.0

0.3.0.0 https://github.com/middlewares/recaptcha

Middleware to use Google reCAPTCHA for spam prevention

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 security server http captcha google recaptcha psr-15

27/11 2016

v0.2.0

0.2.0.0 https://github.com/middlewares/recaptcha

Middleware to use Google reCAPTCHA for spam prevention

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 security server http captcha google recaptcha psr-15

10/10 2016

v0.1.0

0.1.0.0 https://github.com/middlewares/recaptcha

Middleware to use Google reCAPTCHA for spam prevention

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 security server http captcha google recaptcha psr-15