问题描述
当用户输入正确的详细信息时,他将成功登录。但是,如果他错了,则Recaptcha不允许他再次尝试并打印我的错误:'recaptcha_error(2)'
我该如何解决?
HTML-表单+ Recaptcha脚本
<form id="login-form" action="#" >
<input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response">
<input type="hidden" name="action" value="validate_captcha">
<input type="text" name="email">
<input type="password" name="password">
<button type="submit">SEND</button>
</form>
<script src="https://www.google.com/recaptcha/api.js?render=MY_SITE_KEY"></script>
<script>
grecaptcha.ready(function() {
// do request for recaptcha token
// response is promise with passed token
grecaptcha.execute('MY_SITE_KEY',{action:'validate_captcha'})
.then(function(token) {
// add token value to form
document.getElementById('g-recaptcha-response').value = token;
});
});
</script>
if (isset($_POST['g-recaptcha-response'])) {
$captcha = $_POST['g-recaptcha-response'];
} else {
$captcha = false;
}
if (!$captcha) {
$msg = 'recaptcha_error(1)';
} else {
$secret = 'MY_SERVER_KEY';
$response = file_get_contents(
"https://www.google.com/recaptcha/api/siteverify?secret=" . $secret . "&response=" . $captcha . "&remoteip=" . $_SERVER['REMOTE_ADDR']
);
$response = json_decode($response);
if ($response->success === false) {
$msg = 'recaptcha_error(2)';
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)