pablosanches/hcaptcha

A simple wrapper for hCaptcha

dev-master 2021-09-30 11:02 UTC

This package is auto-updated.

Last update: 2024-04-29 04:41:01 UTC


README

hcaptcha header

Quick start

  1. Sign up at hCaptcha.
  2. Fetch your public key and site key from the settings tab.
  3. Get this package composer require pablosanches/hcaptcha
  4. Set up your front end as:
    <head>
        <script src="https://hcaptcha.com/1/api.js" async defer></script>
        ...
    </head>
    <body>
    
    <form action="endpoint.php" method="post">
        ...
        <div class="h-captcha" data-sitekey="your-sitekey"></div>
        <input type="submit" value="send">
    </form>
    
    </body>
  1. Now in your PHP back end:
    require('../vendor/autoload.php');
    use PabloSanches\hCaptcha;

    $hCaptcha = new hCaptcha('your-secret-key');
    $hCaptchaResult = $hCaptcha->challenge($_POST['h-captcha-response']);
    $isHuman = $hCaptchaResult->isHuman(); // True or False
    
    if (!$isHuman) {
        $errors = $hCaptchaResult->getErrors(); // An array with all errors
    }

Enjoy it ;)