function recaptcha_check_answer in reCAPTCHA 7
Same name and namespace in other branches
- 8 recaptcha-php-1.11/recaptchalib.php \recaptcha_check_answer()
- 5.2 recaptcha/recaptchalib.php \recaptcha_check_answer()
- 6 recaptcha-php-1.11/recaptchalib.php \recaptcha_check_answer()
Calls an HTTP POST function to verify if the user's guess was correct
Parameters
string $privkey:
string $remoteip:
string $challenge:
string $response:
array $extra_params an array of extra variables to post to the server:
Return value
2 calls to recaptcha_check_answer()
- example-captcha.php in recaptcha-php-1.11/
example-captcha.php - recaptcha_captcha_validation in ./
recaptcha.module - CAPTCHA Callback; Validates the reCAPTCHA code.
File
- recaptcha-php-1.11/
recaptchalib.php, line 152
Code
function recaptcha_check_answer($privkey, $remoteip, $challenge, $response, $extra_params = array()) {
if ($privkey == null || $privkey == '') {
die("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
}
if ($remoteip == null || $remoteip == '') {
die("For security reasons, you must pass the remote ip to reCAPTCHA");
}
//discard spam submissions
if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
$recaptcha_response = new ReCaptchaResponse();
$recaptcha_response->is_valid = false;
$recaptcha_response->error = 'incorrect-captcha-sol';
return $recaptcha_response;
}
$response = _recaptcha_http_post(RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify", array(
'privatekey' => $privkey,
'remoteip' => $remoteip,
'challenge' => $challenge,
'response' => $response,
) + $extra_params);
$answers = explode("\n", $response[1]);
$recaptcha_response = new ReCaptchaResponse();
if (trim($answers[0]) == 'true') {
$recaptcha_response->is_valid = true;
}
else {
$recaptcha_response->is_valid = false;
$recaptcha_response->error = $answers[1];
}
return $recaptcha_response;
}