How To Install Anti-Spam with reCAPTCHA in PHP

Banner iklan disini
You often find sebel because of spam mails in your guestbook? or generally from the page form that can be accessed by the public? Now the spam-​​spam filter we can in an easy to use reCAPTCHA. ReCAPTCHA Captcha is not just any ordinary, because he is an antidote to the service API for Spam. So you need not bother to make the anti-spam. You just simply register on the site next recaptcha.net put the code and key in a PHP script that we created, right deh :-) For example I install anti-spam using reCaptcha can be found at GampSMS Trial Version Download


01.<html>
02.  <head>
03.    <title>Contoh Form</title>
04.  </head>
05.  <body>
06.     <h1>Contoh Form</h1>
07.     <form method="post" action="submit.php">
08.     Masukkan Input Text <input type="text" name="teks">
09.     <input type="submit" name="submit" value="Submit">
10.     </form>
11.  </body>
12.</html>
submit.php
1.<?php
2.   $input = $_POST['teks'];
3.   echo "Anda telah memasukkan input teks ".$input;
4.?>
The script example above is simple enough that will display the text input entered in the form. Now we will add a captcha on the form above. Furthermore, if the captcha code you entered was incorrect then the input text entered does not appear, but a warning message that the code you entered was incorrect.

Well ... now add a step with reCAPTCHA captcha script is as follows:

The first step, please do register first

Step into two, to register please click 'Use reCaptcha on Your Site'
Captcha PHP
Step three, please click the 'Sign Up'. If you already have a Google account just login.

The fourth step, fill in your website domain name in the box provided. If you want to install on multiple domains site, please unchecked 'Enable this key on all domains (global key)'.
Captcha PHP
Well ... once submitted, you will get a Public Key and Private Key. Please note carefully because both keys will be used to access its reCAPTCHA API.

Step five, download the file 'recaptchalib.php'. This file is the reCAPTCHA library. To download this file, please visit this site.

Step into a six, put the file 'recaptchalib.php' in the directory and the script form processing script formnya.

Step seven, paste this code in the form in order to display the captcha code of its

input.php
01.<html>
02.  <head>
03.    <title>Contoh Form</title>
04.  </head>
05.  <body>
06.     <h1>Contoh Form</h1>
07.     <form method="post" action="submit.php">
08.     Masukkan Input Text <input type="text" name="teks"><br>
09.     <?php
10.        require_once('recaptchalib.php');
11.        $publickey = "...";
12.        echo recaptcha_get_html($publickey);
13.     ?>
14.     <br>
15.     <input type="submit" name="submit" value="Submit">
16.     </form>
17.  </body>
18.</html>
Description:
Fill in your Public Key on his $ publickey.

Step into the eight, we modif his little script follows submit.php

submit.php
01.<?php
02.  require_once('recaptchalib.php');
03.  $privatekey = "...";
04.  $resp = recaptcha_check_answer ($privatekey,
05.                $_SERVER["REMOTE_ADDR"],
06.                $_POST["recaptcha_challenge_field"],
07.                $_POST["recaptcha_response_field"]);
08. 
09.  if (!$resp->is_valid)
10.  {
11.      // output jika kode captcha salah
12.      echo "Maaf kode captcha yang Anda masukkan tidak valid";
13.  }
14.  else
15.  {
16.      // proses jika kode captcha benar
17.      $input = $_POST['teks'];
18.      echo "Anda telah memasukkan input teks ".$input;
19.  }
20.?>

Related Posts

How To Install Anti-Spam with reCAPTCHA in PHP
4/ 5
Oleh