I'm building a website with a form with reCAPTCHA check. As required from Google documentation, I've created a key for the target domain. Then, I've created a form containing reCAPTCHA section
HTML form
<form method="post" action="index.php">
<div class="g-recaptcha" data-sitekey="PUBLIC_KEY"></div>
<input type="submit" name="submit" />
</form>
PHP response check
When form is submitted, reCAPTCHA response is verified (in this example, it's simply printed).
$recaptcha = filter_input(INPUT_POST, 'g-recaptcha-response', FILTER_SANITIZE_STRING);
$googleurl = "https://www.google.com/recaptcha/api/siteverify";
$privatekey = "PRIVATE_KEY";
$remoteip = $_SERVER['REMOTE_ADDR'];
$curl = new Curl($googleurl."?secret=".$privatekey."&response=".$recaptcha."&remoteip=".$remoteip);
$response = json_decode($curl->exec(), true);
print_r($response);
die();
Curl is a class that simply builds a curl request and return result.
The problem
The snippet works fine online and I've checked $response
values both with success and error cases. But during development, I must use it on localhost too. As stated in this post, all keys should work locally. But when I run the code, nothing is shown.