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:
| Key | Data type | Remarks |
|---|---|---|
| success | boolean | true when the API returned success |
| errors | array | Error 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
| Name | Data type | Default | Remarks |
|---|---|---|---|
| $response | string | Token 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']);
}