【发布时间】:2014-11-25 11:58:52
【问题描述】:
最近我的网站收到了大量通过我的付款表单发送的垃圾邮件,我决定需要添加 captcha 以防止这种情况发生。
我正在考虑几个选项,我决定使用 Google 的 reCaptcha。它似乎很容易设置和使用,但我遇到了一些问题。
首先我在表单的标题中包含了这个script:
<script src='https://www.google.com/recaptcha/api.js'></script>
然后我在表单的底部添加了实际的 captcha 本身:
<div class="g-recaptcha" data-sitekey="6LdOVv4SAAAAAJ4muJvo_vD7vsd9T9QIfkEwcO7y"></div>
当我提交表单时,我会执行以下操作:
$captcha = $_POST["g-recaptcha-response"]; //Get Captcha token
$secret_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; //Get Secret key
$google_response = http_get("https://www.google.com/recaptcha/api/siteverify", array("secret"=>$secret, "response"=>$captcha), $info); //perform Get request
print_r($info);
但是什么都没有发生,事实上,以前可以工作的页面只是挂起,甚至没有显示错误消息。有什么想法我可能做错了吗?根据我对文档的理解,响应将在JSON 中,成功将是真或假,如果为真,我想继续付款,如果为假,我想停止并返回表单。
非常感谢任何帮助。或者,如果有人有添加验证码的替代解决方案,我愿意研究一下。
【问题讨论】:
标签: php forms captcha recaptcha