Backend Google ReCaptcha post request

Found this method of doing the ReCaptcha validation, and it is the most simple method I’ve seen/used, although I’ve also used cURL and it worked fine.

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

if($response['success'] == true)
{
    echo 'true';
}else{
    echo 'false';
}

Leave a Reply