php – How do I make a reCAPTCHA check?

Question:

How to check whether the user passed the check in recaptcha or not? For those who do not know: How to send a POST request to the url: https://www.google.com/recaptcha/api/siteverify with parameters: secret, response, remoteip? And the received server response from this request (it issues json there), decode and send by variables?

Google did not help, I ask for examples. Thanks in advance.

Answer:

recaptcha accepts get requests

  $url = 'https://www.google.com/recaptcha/api/siteverify?secret=YOU_SECRET_KEY&response='.(array_key_exists('g-recaptcha-response', $_POST) ? $_POST["g-recaptcha-response"] : '').'&remoteip='.$_SERVER['REMOTE_ADDR'];
$resp = json_decode(file_get_contents($url), true);

if ($resp['success'] == true) {
//все хорошо 
}
else {
// капча не решена
}

you need the captcha to be in the form itself, where you have all the inputs

Scroll to Top