2017 © Pedro Peláez
 

library re-captcha-library

Google ReCAPTCHA (ver. 2) backend provider.

image

dario_swain/re-captcha-library

Google ReCAPTCHA (ver. 2) backend provider.

  • Friday, January 8, 2016
  • by dario_swain
  • Repository
  • 1 Watchers
  • 2 Stars
  • 12,496 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 5 Versions
  • 9 % Grown

The README.md

Google ReCAPTCHA ver.2 backend client

SensioLabsInsight Latest Stable Version Build Status Scrutinizer Code Quality Code Coverage License, (*1)

You can find full documentation about Google reCAPTCHA API v2 here., (*2)

Installation

You can install this package with Composer. Add lines below in your composer.json file:, (*3)

``` json { "require": { "dario_swain/re-captcha-library": "2.0.*" } }, (*4)


or you can use ```composer require``` like here: ``` bash composer require dario_swain/re-captcha-library 2.0.*

Usage Example

Displaying the widget:

<html>
    <head>
        <script src='https://www.google.com/recaptcha/api.js'></script>
    </head>
    <body>
        <form method="post">
            <div class="g-recaptcha" data-sitekey="{RECAPTCHA SITE KEY}"></div>
            <br>
            <input type="submit" name="submit" value="Submit">
        </form>
    </body>
</html>

More about client integration you can find in official docs., (*5)

Verifying the user's response:

``` php <?php, (*6)

$privateKey = 'RECAPTCHA PRIVATE KEY'; //You Google API private key
$clientIp = $_SERVER['REMOTE_ADDR']; //Client IP Address
$gReCaptchaResponse = $_POST['g-recaptcha-response']; //Google reCAPTCHA response

$reCaptchaClient = new Client($privateKey);

try {
    $success = $reCaptchaClient->validate($gReCaptchaResponse, $clientIp);

    if ($success) {
        //Submit form
    }

} catch(ValidationException $e) {
    $validationError = $e->getMessage();
}    

**Simple work example you can find in ```examples/index.php```.** ##Custom Client You can change reCaptcha standard HTTP client to custom client implementation. In this case you can use ```DS\Library\ReCaptcha\Http\Client\ClientInterface``` object. Also you can use any PSR7 comparability HTTP client like ``` php <?php class ProxyClient implements ClientInterface { {@inheritdoc} public function send(RequestInterface $request); { //Your business logic } } ... $proxyHttpClient = new ProxyClient(); $reCaptchaClient = new Client($privateKey, $proxyHttpClient); $reCaptchaClient->validate($gReCaptchaResponse, $clientIp);

Guzzle integration

Instead of standard HTTP client you can use more advanced HTTP client like Guzzle. Now ReCaptchaLibrary support 3.*, 4.*, 5.* and 6.* versions of guzzlehttp/guzzle, (*7)

Guzzle client example:, (*8)


use DS\Library\ReCaptcha\Http\Client\Guzzle\GuzzleClient; $reCaptchaGuzzleClient = new GuzzleClient(); //Guzzle client will be detected automatically //Also you can manually create and initialize Guzzle Client $guzzle = new \GuzzleHttp\Client($configuration); $reCaptchaGuzzleClient = new GuzzleClient($guzzle); $reCaptchaClient = new Client('PRIVATE KEY', $reCaptchaGuzzleClient); $reCaptchaClient->validate($gResponse);

Copyright

Copyright (c) 2015 Ilya Pokamestov dario_swain@yahoo.com., (*9)

The Versions

08/01 2016

dev-master

9999999-dev

Google ReCAPTCHA (ver. 2) backend provider.

  Sources   Download

MIT

The Requires

 

The Development Requires

form validation security psr7 captcha google guzzle recaptcha webservice

08/01 2016

2.0.0

2.0.0.0

Google ReCAPTCHA (ver. 2) backend provider.

  Sources   Download

MIT

The Requires

 

The Development Requires

form validation security psr7 captcha google guzzle recaptcha webservice

06/08 2015

1.x-dev

1.9999999.9999999.9999999-dev

Google ReCAPTCHA (ver. 2) backend provider.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

php library validator captcha recaptcha google api

01/08 2015

1.0.1

1.0.1.0

Google ReCAPTCHA (ver. 2) backend provider.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

php library validator captcha recaptcha google api

09/02 2015

1.0.0

1.0.0.0

Google ReCAPTCHA (ver. 2) backend provider.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

php library validator captcha recaptcha google api