2017 © Pedro Peláez
 

library recaptcha

reCAPTCHA library

image

fruitcakestudio/recaptcha

reCAPTCHA library

  • Wednesday, April 5, 2017
  • by Barryvdh
  • Repository
  • 4 Watchers
  • 14 Stars
  • 13,471 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 7 Versions
  • 8 % Grown

The README.md

reCAPTCHA Library

This is a package to implement reCAPTCHA (https://developers.google.com/recaptcha/), (*1)

Installation

Require this package with composer:, (*2)

composer require fruitcakestudio/recaptcha

Configuration

You can create a new instance by passing the SiteKey and Secret from your API. You can get that at https://www.google.com/recaptcha/admin, (*3)

use FruitcakeStudio\ReCaptcha\ReCaptcha;

$captcha = new ReCaptcha($siteKey, $secret, 'en');

Widget usage

To show the reCAPTCHA on a form, use the class to render the script tag and the widget., (*4)

<?php echo $captcha->getScript() ?>
<form method="POST">
    <?php echo $captcha->getWidget() ?>
    <input type="submit" value="Submit" />
</form>

See https://developers.google.com/recaptcha/docs/display for more options., (*5)

Verifying a response

After the post, use the class to verify the response. You get true or false back. You can access the error codes with $captcha->getErrors() as array, or get a readable message:, (*6)

if ($captcha->verify($_POST["g-recaptcha-response"], $_SERVER["REMOTE_ADDR"])) {
    echo "OK!";
} else {
    echo "FAILED! " . $captcha->getErrorMessage();
}

Note: An error message is not always present., (*7)

You can also let the class discover the POST response and remote IP by using verifyGlobals();, (*8)

if ($captcha->verifyGlobals()) {
    echo "OK!";
}

If you are using Symfony HttpFoundation, you can use the Request object instead of the globals., (*9)

if ($captcha->verifyRequest($request)) {
    echo "OK!";
}

// Or by setting the request before
$captcha->setRequest($request);
if ($captcha->verifyRequest()) {
    echo "OK!";
}

See the docs on https://developers.google.com/recaptcha/docs/verify, (*10)

Laravel integration

Since 0.3.x, Laravel integration is supported with a standalone package: https://github.com/fruitcakestudio/laravel-recaptcha, (*11)

The classes are the same, only the configuration package name is 'laravel-recaptcha' instead of 'recaptcha'., (*12)

The Versions

05/04 2017

dev-master

9999999-dev

reCAPTCHA library

  Sources   Download

MIT

captcha spam recaptcha nocaptcha no captcha

05/04 2017

v0.3.1

0.3.1.0

reCAPTCHA library

  Sources   Download

MIT

captcha spam recaptcha nocaptcha no captcha

15/12 2014

v0.3.0

0.3.0.0

reCAPTCHA library

  Sources   Download

MIT

captcha spam recaptcha nocaptcha no captcha

15/12 2014

v0.2.2

0.2.2.0

reCAPTCHA library

  Sources   Download

MIT

The Development Requires

laravel captcha spam recaptcha nocaptcha no captcha

05/12 2014

v0.2.1

0.2.1.0

reCAPTCHA library

  Sources   Download

MIT

The Development Requires

laravel captcha spam recaptcha nocaptcha no captcha

04/12 2014

v0.2.0

0.2.0.0

reCAPTCHA library

  Sources   Download

MIT

The Development Requires

  • laravel/support 4.2.x

captcha spam recaptcha nocaptcha no captcha

04/12 2014

v0.1.0

0.1.0.0

reCAPTCHA library

  Sources   Download

MIT

captcha spam recaptcha nocaptcha no captcha