- Project page: http://www.google.com/recaptcha/
- Repository: https://github.com/google/recaptcha
- Version: 1.1.0
- License: BSD, see LICENSE
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.
Use Composer to install the library. Either use
composer require google/recaptcha "~1.1"
or add the following to your
composer.json
:
"require": {
"google/recaptcha": "~1.1"
}
First, register keys for your site at https://www.google.com/recaptcha/admin
When your app receives a form submission containing the g-recaptcha-response
field, you can verify it using:
<?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
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.
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)
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