Skip to main content
Version: Fegg 5.x (next)

Turnstile::auth

Verify a Turnstile token

Description​

public array Turnstile::auth( string $response )

Sends the token to https://challenges.cloudflare.com/turnstile/v0/siteverify and returns an array:

KeyData typeRemarks
successbooleantrue when the API returned success
errorsarrayError messages for the API error codes

When the service cannot be reached or does not answer with HTTP 200 JSON, success is false and errors has one message asking the visitor to try again later. A warning is written to the application log.

Arguments​

NameData typeDefaultRemarks
$responsestringToken posted by the widget (cf-turnstile-response)

Example​

Controller
use Fegg\Captcha\Turnstile;

$turnstile = new Turnstile(feggEnv('FEGG_TURNSTILE_SECRET', ''));
$result = $turnstile->auth($this->in('cf-turnstile-response'));

if (!$result['success']) {
$errorMessage = implode(',', $result['errors']);
}