middlewares/recaptcha

Name: recaptcha

Owner: Middlewares

Description: PSR-15 middleware to use Google reCAPTCHA for spam prevention

Created: 2016-10-10 08:13:52.0

Updated: 2018-02-04 18:53:06.0

Pushed: 2018-01-27 19:32:21.0

Homepage: null

Size: 25

Language: PHP

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

middlewares/recaptcha

Latest Version on Packagist Software License Build Status Quality Score Total Downloads SensioLabs Insight

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

Requirements
Installation

This package is installable and autoloadable via Composer as middlewares/recaptcha.

oser require middlewares/recaptcha
Example
patcher = 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>';
}


ponse = $dispatcher->dispatch(new ServerRequest());
Options
__construct(string $secretKey)

The secret API key of your app. You can register it at https://www.google.com/recaptcha/admin

ipAttribute(string $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:

patcher = new Dispatcher([
//detect the client ip and save it in client-ip attribute
new Middlewares\ClientIP(),

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


Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details.

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


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.