reCaptchav2错误消息:我们检测到您的网站正在验证reCAPTCHA通过的解决方案的时间少于50%

时间:2019-03-07 16:28:36

标签: php recaptcha

我将reCaptcha集成到测试表单中,因此我们可以使用reCaptcha来停止bot。在完成所有前端和服务器端代码之后,我想测试用户是否成功完成了reCatpha-但是当我检查reCaptcha管理员时,我看到以下消息:

“我们检测到您的网站在不到50%的时间内验证reCAPTCHA通过的解决方案。这可能表明您与reCAPTCHA集成存在问题。请访问我们的开发者网站以获取更多信息。”

我的服务器端验证在做什么错。我已经检查了Stackoverflow和其他站点的PHP解决方案,但没有任何解决方案。

这是我的代码简化了。

<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Contact | Blah Blah</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script src="https://www.google.com/recaptcha/api.js"></script>
</head>
<body>

<?php
    $responseErr = "";
    $responseMsg = ""; // for debugging purposes
    if($_SERVER["REQUEST_METHOD"] == "POST"){

        // reCaptcha server side integraton
        $secretKey = "secretkey-blahblahblahblahblahblahblahblahblahblah"; // required
        $responseKey = $_POST["g-recaptcha-response"]; // required

        $url = "https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$responseKey";
        $response = file_get_contents($url);
        $responseMsg = "<p>The response is: $response</p>"; // for debugging purposes
        $response = json_decode($response);
        if($response->success){

            // recaptcha validates so continue submitting the form.
            $responseErr = '<p><span style="color:green">* reCaptcha verified</span></p>'; // for debugging purposes
        } else {

            // recaptcha doesn't validate so give the user an error message.
            $responseErr = '<p><span style="color:red">* reCaptcha is required</span></p>';
        }
    }
?>

<form class="recaptchaFrom clearfix" method="post">
    <div class="medium-6 columns">
        <label>Name</label>
        <input type="text" placeholder="Full Name">
    </div>
    <div class="medium-6 columns">
        <label>Email</label>
        <input type="email" placeholder="Email">
    </div>
    <div class="medium-12 columns a-left">
        <div class="g-recaptcha m-bottom" data-sitekey="sitekey-blahblahblahblahblahblahblahblahblahblah"></div>    
        <?php echo $responseMsg; // for debugging purposes ?>
        <?php echo $responseErr; ?>             
    </div>
    <div class="medium-12 columns">
        <input type="submit" name="submit" class="button" value="Submit">
    </div>
</form>

</body>
</html>

2 个答案:

答案 0 :(得分:0)

我在reCAPTCHA管理员中也遇到了相同的错误。传递密钥时,您没有使用过isset,还使用了urlencode函数。这样,希望这能解决您的问题。

if(isset($_POST['captcha']) && !empty( $_POST['captcha'])){
       $response=$_POST['captcha'];

}

$url = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($secret) .  '&response=' . urlencode($response));

答案 1 :(得分:0)

    <?php

        // https://www.youtube.com/watch?v=2NfaBfu_ndc
        $responseErr = "";
        $responseMsg = ""; // for debugging purposes
        if(isset($_POST['submit'])){

            // reCaptcha server side integraton
            $secretKey = "blahblahblahblahblahblahblahblahblahblah"; // required
            $responseKey = $_POST["g-recaptcha-response"]; // required

            $url = "https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$responseKey";
            $responseFile = file_get_contents($url); // send the $url to the Google reCaptcha server for validation and get a response back
            $responseJSON = json_decode($responseFile); // decode the content of the $response
            $debugSKEY = "SECRET KEY is $secretKey"; // for debugging purposes
            if ($responseKey == null){
                $responseKey = '<span style="color:red">empty</span>';
                $urlresponseKey = $responseKey;
            }
            $debugGREC = "G RECAPTCHA RESPONSE is $responseKey"; // for debugging purposes
            $debugURL = "RECAPTCHA URL is $url" . $urlresponseKey; // for debugging purposes
            $debugFILE = "FILE GET CONTENTS is $responseFile"; // for debugging purposes
            if($responseJSON->success == true){

                // recaptcha validates so continue submitting the form.
                $responseErr = '<p><span style="color:green">* reCaptcha verified</span></p>'; // for debugging purposes
            } else {

                // recaptcha doesn't validate so give the user an error message.
                $responseErr = '<p><span style="color:red">* reCaptcha is required</span></p>';
            }
        }
    ?>