PIE ReCAPTCHA
This is a fork of Google's PHP ReCAPTCHA client that allows you to pass cURL options, e.g. to proxy requests over Tor., (*1)
$curl = new ReCaptcha\RequestMethod\CurlPost(null, array(
CURLOPT_PROXY => 'http://127.0.0.1:9050/',
CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5
));
$recaptcha = new \ReCaptcha\ReCaptcha($secret, $curl);
$resp = $recaptcha->verify($gRecaptchaResponse, $remoteIp);
if ($resp->isSuccess()) {
// verified!
} else {
$errors = $resp->getErrorCodes();
}
reCAPTCHA PHP client library
, (*2)
- Repository: https://github.com/paragonie/recaptcha
- Version: 2.1.0
- License: BSD, see LICENSE
Description
reCAPTCHA is a free CAPTCHA service that protect websites from spam and abuse.
This is Google authored code that provides plugins for third-party integration
with reCAPTCHA., (*3)
Installation
Composer (Recommended)
Composer is a widely used dependency manager for PHP
packages. This reCAPTCHA client is available on Packagist as
google/recaptcha
and can be
installed either by running the composer require
command or adding the library
to your composer.json
. To enable Composer for you project, refer to the
project's Getting Started
documentation., (*4)
To add this dependency using the command, run the following from within your
project directory:, (*5)
composer require paragonie/recaptcha "~2.1"
Alternatively, add the dependency directly to your composer.json
file:, (*6)
"require": {
"paragonie/recaptcha": "~2.1"
}
Direct download (no Composer)
If you wish to install the library manually (i.e. without Composer), then you
can use the links on the main project page to either clone the repo or download
the ZIP file. For
convenience, an autoloader script is provided in src/autoload.php
which you
can require into your script instead of Composer's vendor/autoload.php
. For
example:, (*7)
require('/path/to/recaptcha/src/autoload.php');
$recaptcha = new \ReCaptcha\ReCaptcha($secret);
The classes in the project are structured according to the
PSR-4 standard, so you may of course also
use your own autoloader or require the needed files directly in your code., (*8)
Development install
If you would like to contribute to this project or run the unit tests on within
your own environment you will need to install the development dependencies, in
this case that means PHPUnit. If you clone the repo and
run composer install
from within the repo, this will also grab PHPUnit and all
its dependencies for you. If you only need the autoloader installed, then you
can always specify to Composer not to run in development mode, e.g. composer
install --no-dev
., (*9)
Note: These dependencies are only required for development, there's no
requirement for them to be included in your production code., (*10)
Usage
First, register keys for your site at https://www.google.com/recaptcha/admin, (*11)
When your app receives a form submission containing the g-recaptcha-response
field, you can verify it using:, (*12)
<?php
$recaptcha = new \ReCaptcha\ReCaptcha($secret);
$resp = $recaptcha->verify($gRecaptchaResponse, $remoteIp);
if ($resp->isSuccess()) {
// verified!
} else {
$errors = $resp->getErrorCodes();
}
You can see an end-to-end working example in
examples/example-captcha.php, (*13)
Upgrading
From 1.0.0
The previous version of this client is still available on the 1.0.0
tag in
this repo but it is purely for
reference and will not receive any updates., (*14)
The major changes in 1.1.0 are:
* installation now via Composer;
* class loading also via Composer;
* classes now namespaced;
* old method call was $rc->verifyResponse($remoteIp, $response)
, new call is
$rc->verify($response, $remoteIp)
, (*15)
Contributing
We accept contributions via GitHub Pull Requests, but all contributors need to
be covered by the standard Google Contributor License Agreement. You can find
instructions for this in CONTRIBUTING, (*16)