我最近移动了服务器,并且自从移动以来,我的Recaptcha失败了服务器端验证检查。我已经仔细检查了站点密钥和秘密密钥,它们是否匹配。
function captchaVerify() {
$privateKey = "matches recaptcha dashboard";
$response;
if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) {
$response = $_POST['g-recaptcha-response'];
} else {
echo "bad POST response ";
echo $response;
return false;
}
if (isset($response) && !empty($response)) {
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = [
'secret' => $privateKey,
'response' => $response
];
$options = [
'http' => [
'method' => 'POST',
'content' => http_build_query($data)
]
];
$context = stream_context_create($options);
$verify = file_get_contents($url, false, $context);
$captcha_success = json_decode($verify);
if ($captcha_success->success == false) {
//fails here
echo "success false ";
echo $response;
return false;
} else {
return true;
}
} else {
echo "empty or not set ";
echo $response;
return false;
}
}
编辑:
var_dump($response)
按顺序输出由334个数字和字母组成的字符串
var_dump($data)
输出与$ privateKey匹配的私钥,与reCAPTCHA控制台匹配的私钥,后跟gobbledygook响应
var_dump($context)
输出resource(13)
var_dump($verify)
输出BOOL(false)
var_dump($captcha_success)
输出NULL
我不确定还有什么地方可以解决