PHP code example of widerplan / hcaptcha

1. Go to this page and download the library: Download widerplan/hcaptcha library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

widerplan / hcaptcha example snippets




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...
}



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...
}