1
我正在用reCAPTCHA检查构建一个带有窗体的网站。根据Google documentation的要求,我为目标域创建了一个密钥。然后,我创建了一个包含验证码段ReCAPTCHA在本地主机上不工作
HTML表单
<form method="post" action="index.php">
<div class="g-recaptcha" data-sitekey="PUBLIC_KEY"></div>
<input type="submit" name="submit" />
</form>
形式
PHP应答确认
当提交表单时,验证码的响应进行验证(在这个例子中,它只是打印)。
$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是一个简单地构建一个curl请求并返回结果的类。
问题
代码段工作正常在线和我检查$response
都与成功和错误的情况下的值。但在开发过程中,我也必须在本地主机上使用它。如this post所述,所有密钥都应该在本地工作。但是当我运行代码时,什么都没有显示。