Jump to content

Help integrating Re-captcha into a website template


ApeirogonGames

Recommended Posts

Hey guys. 

I recently purchased a website template from ThemeForest and it uses Mailchimp.php to send mail via the contact form. Unfortunately it doesn't have a recaptcha integrated and I'm getting about a dozen spam form submits a day. I was trying to integrate google's recaptcha into the form, but I haven't been able to get it to work. I followed the instructions that google provided but they're obviously above my head. They made it seem so easy, but when I tried to add it in, the form just gets stuck in a loop trying to send.

 

They say to create a php file called verify.php with this code:

<?php
  require_once('recaptchalib.php');
  $privatekey = "your_private_key";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

  if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
         "(reCAPTCHA said: " . $resp->error . ")");
  } else {
    // Your code here to handle a successful verification
  }
  ?>

and my template uses a file called send-email.php so I'm guessing all I have to do is call the send-email.php file in the section that says "Your code here to handle a successful verification" but I have no idea how to do that.

 

Thanks so much for any help!

Link to comment
Share on other sites

I don't know where you got your information from, but reCAPTCHA 1.0 (the version you're trying to use) has been abandoned many years ago. The official documentation has a big red warning sign explicitly saying that.

 

So it's no surprise that none of this works. The current version is reCAPTCHA V2 (read the manual on how verification works). There's also the new Invisible reCAPTCHA.

Link to comment
Share on other sites

From the google Recaptcha website.

 

That's not possible, because those instructions are completely different from the instructions and code you cited in your first post (which refer to a long abandoned version).

 

Anyway, delete the code and stay away from wherever you got it from. The current instructions tell you to make a POST request to

https://www.google.com/recaptcha/api/siteverify

with the parameters secret (which you got during registration), response (the value from the reCAPTCHA form field) and optionally remoteip (the user's IP address).

 

And that's what you'll have to do. If you don't have an HTTP library yet, use cURL. There are several examples for making a POST request.

Link to comment
Share on other sites

The code I posted is the send mail php code from the website template. I didn't post the recaptcha code.

Maybe I should just look into a free form mailing program, it might be easier and likely to stay up to date with the current apis. I think this is probably too far above my skill level to implement.

Thanks for the help though Jacques.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.