我的网站同时提供了Recaptcha v1和通用的验证码方法, 然后我决定将我的Recaptcha v1升级到Recaptcha v2 所以我将所有来自Google ReCaptcha git的文件放到了我的网站上。 因此,现在显示的是验证码,但是每次我单击“提交”按钮时,都会显示无效的验证码。
当前用户注册表中包含用于验证验证码的代码
if(!$captcha->is_valid()) {
$_SESSION['error'][] = $language->global->error_message->invalid_captcha;
}
我相信问题的根源在于这部分代码
/* Custom valid function for both the normal captcha and the recaptcha */
function is_valid() {
if($this->recaptcha) {
$recaptcha = new \ReCaptcha\ReCaptcha($this->recaptcha_private_key);
$response = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
return ($response->is_valid);
} else {
return ($_POST['captcha'] == $_SESSION['captcha']);
}
}
答案 0 :(得分:0)
我找到了解决方法
/* Custom valid function for both the normal captcha and the recaptcha */
function is_valid() {
if($this->recaptcha) {
$recaptcha = new \ReCaptcha\ReCaptcha($this->recaptcha_private_key);
$resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
return ($resp->isSuccess());
} else {
return ($_POST['captcha'] == $_SESSION['captcha']);
}
}