Skip to content

kiddivouchers/hcaptcha

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
Aug 29, 2024
Aug 29, 2024
Aug 29, 2024
Aug 29, 2024
Aug 9, 2024
Aug 14, 2024
Aug 14, 2024
Aug 14, 2024
Aug 14, 2024
Aug 14, 2024
Aug 14, 2024
Aug 29, 2024
Aug 28, 2024
Aug 29, 2024

Repository files navigation

hCaptcha API Client

Usage

Basic

With php-http/discovery installed this package will be leveraged to attempt to use the most appropriate implementations of PSR-7 and PSR-18.

composer require widerplan/hcaptcha php-http/discovery
<?php

declare(strict_types=1);

use WiderPlan\Hcaptcha\Client;

$client = Client::create(getenv('HCAPTCHA_SECRET'));
$result = $client->verify($_POST['h-captcha-response'], getenv('HCAPTCHA_SITE_KEY'));

if ($result->success) {
    // Perform protected action...
}

With custom components

Instead of relying on the automatic discovery you can wire up your chosen implementations.

composer require widerplan/hcaptcha symfony/http-client slim/psr7
<?php

declare(strict_types=1);

use Slim\Psr7\Factory;
use Symfony\Component\HttpClient\Psr18Client;
use WiderPlan\Hcaptcha\Client;

$httpClient = new Psr18Client(
    null,
    new Factory\ResponseFactory(),
    new Factory\StreamFactory(),
);
$client = Client::create(getenv('HCAPTCHA_SECRET'), $httpClient);
$result = $client->verify($_POST['h-captcha-response'], getenv('HCAPTCHA_SITE_KEY'));

if ($result->success) {
    // Perform protected action...
}