Implementing Recaptcha on a Form

Posted on 2014-08-27
Last Modified: 2014-08-29
A form on my website has recently been inundated with SPAM bots that are resulting in a lot of SPAM entries in the database. I would like to implement recaptcha on the form. I went to the Google Recaptcha site, entered the domain name and obtained the public and private keys and uploaded the recaptcalib.php to the relevant directory. I placed the code relating to the public key before the "Submit" button in the form, but am not quite sure where to put the code relating to the private key, i.e.,

require_once(dirname(__FILE__) . "/../recaptchalib.php");
        $privatekey = "Privatekeydigits...";
        $resp = recaptcha_check_answer ($privatekey,
        if (!$resp->is_valid) {
          // What happens when the CAPTCHA was entered incorrectly
          die("The reCAPTCHA numbers/letters did not match the image. Please click your browser's back button and try it again.");

I believe it has to go where the onsubmit() function in the form is but am not quite sure where to put it.

I would appreciate any help on this.
Question by:geeta_m9
    LVL 82

    Accepted Solution

    The part starting with require_once(dirname(__FILE__) . "/../recaptchalib.php"); goes on the PHP page that the form POSTs to, your 'action' page.  However, I don't think your 'servlet.webtolead ' page will support the PHP code.  Here's some code for JAVA:
    LVL 107

    Assisted Solution

    by:Ray Paseur
    If you can access and modify the PHP files that create and process your scripts, there are many different ways of implementing a CAPTCHA test without using ReCaptcha, which has been broken repeatedly by several attackers.  This article shows some of the ways that may not yet be subject to successful attacks.

    If you do not know where to put the code after you have read the article, please be respectful of your time and consider hiring a professional developer to help with the work.  It will not cost very much and it will save you a great deal of time!

    Author Comment

    Thank you for your suggestion, Ray. Can you suggest a site or sites where I may be able to find someone to hire to help me fix this problem?

    LVL 107

    Expert Comment

    by:Ray Paseur
    Sure - this one!  Many of the E-E community have "hire me" buttons on their profiles.  Here's a link to my profile.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
    Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
    In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
    The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now