nietonfir / google-recaptcha
Library to simplify the server-side validation of Google's 'No CAPTCHA reCAPTCHA'
Installs: 9 423
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: >=5.4.0
- guzzlehttp/guzzle: ~5.1
Requires (Dev)
- phpdocumentor/reflection-docblock: ^2.0
- phpunit/phpunit: ~4.8
- symfony/phpunit-bridge: ^3.2
- symfony/yaml: ~2.1
This package is not auto-updated.
Last update: 2024-10-26 17:56:02 UTC
README
ReCAPTCHA is a free CAPTCHA service that protect websites from spam and abuse. This library aims to providate an alternative to the official ReCAPTCHA library for verifying a users "No CAPTCHA reCAPTCHA" response. Internally it uses Guzzle for communicating with the ReCAPTCHA API.
Installation
The recommended way to install GoogleReCaptcha is through Composer.
# Install Composer curl -sS https://getcomposer.org/installer | php
Next, run the Composer command to install the latest stable version of GoogleReCaptcha:
composer require "nietonfir/google-recaptcha"
Or add GoogleReCaptcha in your composer.json
"require": { "nietonfir/google-recaptcha": "~0.0" }
and tell Composer to install the library:
composer update "nietonfir/google-recaptcha"
After installing, you need to require Composer's autoloader:
require 'vendor/autoload.php';
Usage
A sample validation client could look like the following:
use GuzzleHttp\Client; use Nietonfir\Google\ReCaptcha\ReCaptcha; use Nietonfir\Google\ReCaptcha\Api\RequestData, Nietonfir\Google\ReCaptcha\Api\ResponseFactory; $requestData = new RequestData( 'YOUR_API_SECRET_HERE', // secret $_POST['g-recaptcha-response'], // user response $_SERVER['REMOTE_ADDR'] // end user IP ); $reCaptcha = new ReCaptcha(new Client(), new ResponseFactory()); $response = $reCaptcha->processRequest($requestData); if ($response->isValid()) { // check the hostname if "Domain Name Validation" is turned off // if($_SERVER['SERVER_NAME'] === $response->getHostName()) { … } echo 'I\'m not a robot'; } else { var_dump($response->getErrors()); }