-5

I added Google ReCaptcha but it does not seem to work.

I use one index.html in which i have my form and a file.php to send the form.

In my console, i am at the "integration" in the "Verify the reCAPTCHA token" section and I am stuck here. I want to use the php method but I don't understand 2 things:

  1. What does "require 'vendor/autoload.php';" mean in the beginning of the code?
  2. Where do I paste this code?

I did paste the code from "Add reCAPTCHA to your website" section in my html file but it is the integration where I am stuck.

This is my form in my index.php:

  <form action="submit-form.php" method="POST" class="space-y-4" name="gtld">
    <input type="text" name="company" placeholder="Company Name" required class="w-full p-3 border border-gray-300 rounded" />
    <input type="text" name="contact" placeholder="Contact Person" required class="w-full p-3 border border-gray-300 rounded" />
    <input type="url" name="website" placeholder="Website" required class="w-full p-3 border border-gray-300 rounded" />

    <fieldset class="border p-4 rounded">
      <legend class="text-lg font-medium">Services Offered</legend>
      <div class="space-y-2 mt-2">
        <label class="block"><input type="checkbox" name="services[]" value="Application writing and submission" /> Application writing and submission</label>
        <label class="block"><input type="checkbox" name="services[]" value="Provide advice and identify resources" /> Provide advice and identify resources</label>
        <label class="block"><input type="checkbox" name="services[]" value="Legal services" /> Legal services</label>
        <label class="block"><input type="checkbox" name="services[]" value="Backend Registry provider" /> Backend Registry provider</label>
      </div>
    </fieldset>

    <textarea name="about" maxlength="300" placeholder="About the Company (max 300 characters)" class="w-full p-3 border border-gray-300 rounded" required></textarea>

    <button class="g-recaptcha"
        data-sitekey="8LcIiKwrAAAAAPyi7EBe1oNCmVORx_SYxdLVpAtk"
        data-callback='onSubmit'
        data-action='submit'>
        Submit
    </button>
  </form>

I added the first necessary Google captcha scripts for the html button

I added the second script and changed the "demo-form" to the name of my form so it matches:

<script>
  function onSubmit(token) {
    document.getElementById("demo-form").submit();
  }
</script>

I also added the third script to my index.html as given by Google in its interface for my project/:

<button class="g-recaptcha"
    data-sitekey="6LcIiKwrAAAAAPyi7EBe1oNCmVORx_SYxdLVpAtk"
    data-callback='onSubmit'
    data-action='submit'>
  Submit
</button>

THEN, the next step is to "Verify the reCAPTCHA token" with the various methods given by Google captcha.

I tried the REST API creating a "request.json" file and added the code suggested inside:

{
  "event": {
    "token": "TOKEN",
    "expectedAction": "USER_ACTION",
    "siteKey": "8LcIiKwrAAAAAPyi7EBe1oNCmVORx_SYxdLVpAtk",
  }
}

When all this is online, I proceeded with the next step "Send an HTTP POST request with the saved JSON data to the url below."

The URL below is : https://recaptchaenterprise.googleapis.com/v1/projects/annuaire-1755692338178/assessments?key=API_KEY (I changed the API_KEY to the one I created) butwhen enter the URL in my browser, I get a "his recaptchaenterprise.googleapis.com page can’t be found" : is in the browser that I should enter this URL ?

If yes...then what do I do wrong?

1
  • 1
    You seem to be confused between standard ReCaptcha and Enterprise Recaptcha. Make sure you use the right version of the documentation - see developers.google.com/recaptcha Commented Aug 24, 2025 at 23:22

1 Answer 1

2

Thats the enterprise URL. It needs Google Cloud setup if Im not mistaken. You probably want to use the normal recaptcha v2/3. You cant open the URL in browser as it need a POST and more setup. The require is for googles library, but you don't need that. Just integrate with something like this:

<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $recaptchaSecret = "YOUR_SECRET_KEY"; // Secret NOT the site key
    $recaptchaResponse = $_POST['g-recaptcha-response'];

    // Verify token with Google
    $url = 'https://www.google.com/recaptcha/api/siteverify';
    $data = [
        'secret' => $recaptchaSecret,
        'response' => $recaptchaResponse,
        'remoteip' => $_SERVER['REMOTE_ADDR']
    ];

    $options = [
        'http' => [
            'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
            'method'  => 'POST',
            'content' => http_build_query($data)
        ]
    ];

    $context  = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    $verification = json_decode($result);

    if ($verification->success) {
        // success captcha passed
        echo "Form submitted successfully!";
    } else {
        // captcha failed
        echo "reCAPTCHA verification failed.";
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Will try this but I am concerned with the Enterprise URL which kind of "forces me " to create a project, etc... anyway. Thanks.
Don't understand why you're forced to use the enterprice URL...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.