ReCAPTCHA::auth
Verify a reCAPTCHA token
Description
public array ReCAPTCHA::auth( string $response, [ float $threshold = null ] )
Sends the token to https://www.google.com/recaptcha/api/siteverify and returns an array:
| Key | Data type | Remarks |
|---|---|---|
| success | boolean | true when the API returned success, the score is not below the threshold and there is no error |
| errors | array | Error messages (English for the API error codes; a Japanese message when the score is below the threshold) |
When the service cannot be reached, success is false (see When the service cannot be reached).
Arguments
| Name | Data type | Default | Remarks |
|---|---|---|---|
| $response | string | Token posted by the widget (g-recaptcha-response) | |
| $threshold | float | null | Minimum score for this call. null: the threshold given to the constructor |
Example
Controller
use Fegg\Tool\Captcha\ReCAPTCHA;
$recaptcha = new ReCAPTCHA(feggEnv('FEGG_RECAPTCHA_SECRET', ''), 0.5);
$result = $recaptcha->auth($this->in('g-recaptcha-response'));
if (!$result['success']) {
$errorMessage = implode(',', $result['errors']);
}