Google reCaptcha v3将成功归为false

I am testing my user login/registration system. I finally finished the form and I have been testing the form for a while now. It was working before I got the form finished and it works perfectly fine on another page however, it won't work on my page for registration. It keeps sending the success as false. My other page is a contact form and it's not that different from my registration page. It has all the same files inside.

My error code keeps showing me that I'm a bot when I'm clearly not a bot and I'm just testing out my own code.

I thought before there was a problem with where the code was stored in the directory at first, so I tried that.

Then, I thought that if I changed the keys, then maybe I would manage to get the system to work again. That didn't work.

Finally, I tried rearranging my html code to get it to work and that didn't work either.

Now, the crazy part, I'm still getting a score of 0.9 (checked on recaptcha site), which is enough for me to pass as a human but, it's still giving me that error within the JSON.

It worked fine before but, as soon as I started to test my input validation for my registration form, it began to call my response a false.

This is the error I keep getting. I wasn't too sure about formatting a JSON. This was returned with the php function var_dump. It was technically just one line.

    object(stdClass)#13 (2) 
    { 
        ["success"]=> bool(false)
        ["error-codes"]=> array(1) 
        { 
           [0]=> string(22) "missing-input-response" 
        }
    }

This is the script I have in a file called recaptcha.php

    <script src='https://www.google.com/recaptcha/api.js?render=<?php echo SITE_KEY; ?>'></script>
    <script>
      grecaptcha.ready(function() {
          grecaptcha.execute('<?php echo SITE_KEY; ?>', {action: 'homepage'}).then(function(token) {
             document.getElementById('g-recaptcha-response').value=token;
          });
      });
      </script>

EDIT/

Added some additional code. A php function. The constant SECRET_KEY is defined as a global variable in another file.

    function getCaptcha($secretKey) {
        $response = 
    file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . SECRET_KEY . "&response={$secretKey}");
        $reCaptcha = json_decode($response);
        return $reCaptcha;
    }

This is included where I verify the recaptcha.

   $reCaptcha = getCaptcha($_REQUEST['g-recaptcha-response']);
       var_dump($reCaptcha);

If that helps.

I'm expecting it to turn into ["success"]=> bool(true) but, I don't even have the slightest clue what's wrong. I'm ready to get Google on the phone just to solve this issue. Can anyone help?

This error means that you're not passing in the site 'secret' param to the POST request to: https://www.google.com/recaptcha/api/siteverify

Check that the 'secret' param (called SECRET KEY in the settings screen of the admin area), is correct and is being sent in the POST request.

Okay, so after looking at a few things, I found out why it kept returning as a "missing-input" error.

I had a page with two forms and only one recaptcha.

    <form>
    <input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response" />
    </form>
    <form>
    <input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response" />
    </form>

Because there were two of them, the API didn't know which to distinguish and instead of assigning the same value to both, it assigned no value to either. So, in-order to fix this I changed my javascript to this:

<script src='https://www.google.com/recaptcha/api.js?render=<?php echo SITE_KEY; ?>'></script>
    <script>
      grecaptcha.ready(function() {
          grecaptcha.execute('<?php echo SITE_KEY; ?>', {action: 'homepage'}).then(function(token) {
             document.getElementById('g-recaptcha-response').value=token;
             document.getElementById('g-recaptcha-response2').value=token;
          });
      });
      </script>

And my input form looked something like this:

    <form>
    <input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response" />
    </form>
    <form>
    <input type="hidden" id="g-recaptcha-response2" name="g-recaptcha-response2" />
    </form>

The same value but, put into two separate fields. Even if you are using the second field for just one page, it's okay to leave it in there because it won't affect a page with just one recaptcha. As long as the first field is used to store the token and is reference in your html. I also changed this in the php.

    $reCaptcha = getCaptcha($_REQUEST['g-recaptcha-response2']);
       var_dump($reCaptcha);

I guess for anyone building a page with multiple forms, if you want to use recaptcha, you will need to distinguish two different input fields to receive the token. After spending nearly a day on this, I can't believe it took me that long to figure out something so simple. This will solve the missing-input error as well as the invalid-input error.