PHP code example of wearesho-team / recaptcha-v3

1. Go to this page and download the library: Download wearesho-team/recaptcha-v3 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/ */

    

wearesho-team / recaptcha-v3 example snippets




use Wearesho\ReCaptcha;

$response = $_POST['g-recaptcha-response'];
$ip = $_SERVER['REMOTE_ADDR'] ?? null;

$config = new ReCaptcha\V3\Config($secret = "...");
$client = new ReCaptcha\V3\Client($config);

try {
    $response = $client->verify($response, $ip);
} catch (ReCaptcha\V3\Exception $e) {
    $response = $e->getResponse();
    // do something if token is not valid
}

$response->getScore(); // score from 0 to 1