Monday, March 03, 2014

reCAPTCHA Library for PHP - Learnmore @i-visionblog.com

The world is very competitive and every one tries to uphold the growth of others or promote their contents through SPAM E-mail,comments and through various aspects.So,let us see how to prevent SPAM submissions by using reCAPTCHA to validate user input and proving that user is a human being and not a ROBOT.This generally used to prevent users to make spam on site and increase duplication of data.Hope this technique may control to some extent because human become monotonous to such validation on reading the real life image and answer it in correct manner.


download library  -  Live DEMO 


First Register your DOMAIN and get your unique private & public Key.visit here to register

after registration try to get the the public and private.

then now let us set up a form for submission and try to reduce the spam actions that are over thrown on your form.

PHP & HTML code:



 <html>
  <body>
    <form action="" method="post">
<?php

require_once('recaptchalib.php');

// Get a key from https://www.google.com/recaptcha/admin/create
$publickey = "YOUR_PUBLIC_KEY";
$privatekey = "YOUR_PRIVATE_KEY";

# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;


if ($_POST["recaptcha_response_field"]) {
        $resp = recaptcha_check_answer ($privatekey,
                                        $_SERVER["REMOTE_ADDR"],
                                        $_POST["recaptcha_challenge_field"],
                                        $_POST["recaptcha_response_field"]);

        if ($resp->is_valid) {
                echo "You got it!";
#REST OF YOUR CODE HERE TO UPDATE IN DATABASE OR VARIOUS OPTIONS TO PERFORM
        } else {
                # set the error code so that we can display it
                $error = $resp->error;
        }
}
echo recaptcha_get_html($publickey, $error);
?>
    <br/>
    <input type="submit" value="submit" />
    </form>
  </body></html>    

the above code include recaptchalib.php file in your download folder,just include it in the form to manage the spam.this form automatically detects the error and process the form accordingly.you can add the check up in the another file instead of same file in PHP.

you can customize the Recaptcha theme also- read here

if any bugs report as comments and feel free to share and prevent spam better using google web services.

5 comments:

Anonymous said...

Nice work good information

Anonymous said...

Still please update for separate form also
Pls sir!!
[email protected]

Anonymous said...

After submitting the recaptcha appears again
-harish

shivasurya said...

then place your checklib script in some other php file and apply action to it through the form!

shivasurya said...

just place the
check lib script in another page and try !

Post a Comment

feel free to post your comments! Don't Spam here!