Php Recaptcha在活动站点上始终无效
在我的本地机器上似乎可以验证,但当我将其上传到我的实时站点时,它总是失败。我转储了应答/响应对象,如下所示:Php Recaptcha在活动站点上始终无效,php,captcha,recaptcha,Php,Captcha,Recaptcha,在我的本地机器上似乎可以验证,但当我将其上传到我的实时站点时,它总是失败。我转储了应答/响应对象,如下所示: ReCaptchaResponse::__set_state(array( 'is_valid' => false, 'error' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"', )) array ( *snip* 'recaptcha_challenge_field'
ReCaptchaResponse::__set_state(array(
'is_valid' => false,
'error' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"',
))
array (
*snip*
'recaptcha_challenge_field' => '03AHJ_VuvqpAkJnmfOZHHf80EPt85lVEeq9IRuO9zw1jZ1fzUk-_DAw0z2k3-TeXzAXQVXUWChyCGnC1RoXRPly4Ldz0FugPKW_WKWEoKysNLnpcv2xvyWONpq0VDV3ipsy5Vukui0zxlSqiBBWw00VYPSkO52OqMv_A',
'recaptcha_response_field' => 'uterf sw',
)
POST /recaptcha/api/verify HTTP/1.0
Host: www.google.com
Content-Type: application/x-www-form-urlencoded;
Content-Length: 272
User-Agent: reCAPTCHA/PHP
privatekey=<<MY INFO HERE>>&challenge=<<BLAH>>...
验证代码:
$recaptcha_answer = recaptcha_check_answer('MY_PRIVATE_KEY_HERE', $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']);
if(!$recaptcha_answer->is_valid) {
$validation_errors[] = 'The reCAPTCHA you entered was not correct';
echo '<!-- '.var_export($recaptcha_answer,true).var_export($_POST,true).' -->';
}
但我得到的回复看起来不像是来自谷歌。这是一个“禁止访问”页面。我想知道是否有什么东西在拦截它…我发现了问题。由于谷歌没有回复,我尝试查找IPs:
echo 'www.google.com: '. gethostbyname('www.google.com').'<br/>';
echo '<offending site>: '. gethostbyname('<offending site>');
echo“www.google.com:”。gethostbyname('www.google.com')。
;
回音“:”。gethostbyname(“”);
当我在我的服务器上运行时,它们是一样的!有人搞砸了主机查找。啊 这是Google reCaptcha吗?还有,你用什么代码来验证验证码本身?@Sammaye:是的,Google recaptcha。现在发布代码。您在获取reCaptcha密钥时指定了您的域名吗?还是它是公开的?@AzizAG:我选择了一个“全局密钥”。但是域名是正确的,尽管没有
www.
Poop:(我讨厌共享主机,因为这些原因,API从来没有发挥应有的作用,你通常不得不胡闹。
POST /recaptcha/api/verify HTTP/1.0
Host: www.google.com
Content-Type: application/x-www-form-urlencoded;
Content-Length: 272
User-Agent: reCAPTCHA/PHP
privatekey=<<MY INFO HERE>>&challenge=<<BLAH>>...
echo 'www.google.com: '. gethostbyname('www.google.com').'<br/>';
echo '<offending site>: '. gethostbyname('<offending site>');