Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Re Captcha Library Laravel Package

dario_swain/re-captcha-library

PHP backend client for Google reCAPTCHA v2. Validate the user’s g-recaptcha-response token against Google using your secret key (optionally passing the client IP) to confirm form submissions and block bots. Composer-installable and lightweight.

View on GitHub
Deep Wiki
Context7

#Google ReCAPTCHA ver.2 backend client

SensioLabsInsight Latest Stable Version Build Status Scrutinizer Code Quality Code Coverage License

You can find full documentation about Google reCAPTCHA API v2 here.

##Installation

You can install this package with Composer. Add lines below in your composer.json file:

{
    "require": {
        "dario_swain/re-captcha-library": "2.0.*"
    }
}

or you can use composer require like here:

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.

####Verifying the user's response:

<?php

    $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
    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

Guzzle client example:


    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.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony
spatie/flare-daemon-runtime