用户输入了错误的详细信息,则无法再次尝试登录

问题描述

我有一个带有Recaptcha 3脚本的登录表单。

用户输入正确的详细信息时,他将成功登录。但是,如果他错了,则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>

我的PHP部分(在我的ajax文件中)

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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...