reCAPTCHA:为什么我不能两次检查相同的结果? [英] reCAPTCHA: why can't I check the same result twice?

查看:94
本文介绍了reCAPTCHA:为什么我不能两次检查相同的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的意思是,如果我检查第一个客户输入,并且确定第二次输入相同的输入始终是错误的...
为什么?

I mean if I check first clients input and it is OK the second check of the same input is always false... Why is that?

我真的需要能够检查两次(一次用于客户端验证,第二次用于服务器端验证)

I really need ability to check it twice (one for client side validation and second for server side validation)

谢谢!!!

编辑

澄清:

如果用户的输入正常,Recaptcha返回true(我通过ajax到我的服务器,服务器将请求发送到Recaptcha的服务器),表单正在提交并通过POST发送,还有两个变量: recaptcha_challenge_field value和 recaptcha_response_field 值(已经检查过),然后我的服务器要求recaptcha的服务器再次检查这两个值以进行服务器端验证。

If user's input is ok and recaptcha returns true (I do it through ajax to my server which sends request to recaptcha's server) the form is submitting and sends via POST also 2 variables: recaptcha_challenge_field value and recaptcha_response_field value (which was already checked) and than my server asks recaptcha's server to check again this two values to do server side validation.

Jquery代码:

$("#form_id").find("button").click(function(){
    var c = $("#recaptcha_challenge_field").val(),
        r = $("#recaptcha_response_field").val();

    $.ajax({
        url: "/ajax/captcha?challenge=" + c + "&response=" + r,
        dataType: "json",
        success: function(data){
            if(data['is_valid']){
                $.ajax({
                    url: "/ajax/captcha?challenge=" + c + "&response=" + r,
                    dataType: "json",
                    success: function(data){
                        if(data['is_valid']){
                            alert('OK');
                        }else{
                            alert('FAILED');
                        }
                    }
                });
            }else{
                Recaptcha.reload();
            }
        }
    });
    return false;
});

因此,如您所见,存在两个绝对相同的操作,但结果不同(它仅警告失败)。

So, as you can see there are two absolutely identical operations with different result (it alerts only FAILED).

推荐答案

因为它存储在一个会话中,因此在提交结果时将其清除。在页面加载时,将为该CAPTCHA值生成一个新的会话变量。

Because it is stored in a session that is cleared when the result is submitted. On page load, a new session variable for that CAPTCHA value is generated.

这篇关于reCAPTCHA:为什么我不能两次检查相同的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆