[英]How to validate Recaptcha in this case?
my website has both recaptcha v1 and a generic captcha method for validation, then i decided to upgrade my recaptcha v1 to recaptcha v2 so i placed all files from Google ReCaptcha git and placed on my website. 我的网站同时具有recaptcha v1和通用的验证码方法,因此我决定将我的recaptcha v1升级到recaptcha v2,因此我将所有来自Google ReCaptcha git的文件放在了我的网站上。 So captcha is showing now, but every time i click the submit button it shows invalid captcha.
因此,现在显示的是验证码,但是每次我单击提交按钮时,它都会显示无效的验证码。
currently user registration form has this code to validate recaptcha 当前用户注册表单具有此代码以验证验证码
if(!$captcha->is_valid()) {
$_SESSION['error'][] = $language->global->error_message->invalid_captcha;
}
and i believe the source of problem is from this part of code 而且我相信问题的根源在于这部分代码
/* 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']);
}
}
I found the solution 我找到了解决方案
/* 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']);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.