wobeto/google-recaptcha-checkbox

Service to validate Google recaptcha checkbox

1.2 2021-05-28 00:34 UTC

This package is auto-updated.

Last update: 2024-04-28 07:09:18 UTC


README

To install via composer, run:

composer require wobeto/google-recaptcha-checkbox

Register a new site on https://www.google.com/recaptcha/admin

Include the follow script to your site

<script src="https://www.google.com/recaptcha/api.js?hl=pt-BR"></script>

Include the google div recaptcha inside form tag and the site key in the data-sitekey attribute

<div class="g-recaptcha" data-sitekey="site-key"></div>

PHP server use:

<?php

include 'vendor/autoload.php';

use Wobeto\GoogleRecaptchaCheckbox\Recaptcha;

try {
    $secret = '4Lchd-IvAAeAAIWBvzYvAEKu1chTimd0HJroP9T4';
    
    $recaptcha = new Recaptcha($secret);

    $verify = $recaptcha->verify($_POST['g-recaptcha-response']);

    var_dump($verify); //true
} catch (Exception $e) {
    echo $e->getMessage();
}

Enjoy...