widerplan / hcaptcha
hCaptcha API client
v1.0.0
2024-09-03 11:18 UTC
Requires
- php: >= 8.1
- psr/http-client: ^1.0
- psr/http-client-implementation: *
- psr/http-factory-implementation: *
- webmozart/assert: ^1.11
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.8
- nyholm/psr7: ^1.8
- php-http/discovery: ^1.17
- symfony/http-client: ^6.4 || ^7.1
- symfony/var-dumper: ^6.4 || ^7.1
Suggests
- php-http/discovery: For automatic discovery and configuration of HTTP client.
This package is auto-updated.
Last update: 2025-03-24 12:32:32 UTC
README
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... }