How to Add Recaptcha in your Website [php]

How to add ReCaptcha? this is not so difficult for you when you read this article. You can add ReCaptcha in any form, word press, php, HTML, JavaScript, asp.net page. Now the first Question is:

reCAPTCHA

Why we use recaptcha?

Sometimes when you make submit the form on your website for the e.g-Contact page, signup page etc.. Then you get a lot of people sign up or contact you by name like this asfdsgas, sdgsfd, fhgfdre . This is nothing but someone spam your website.So do not worry ! by ReCaptcha you can stop this.Now

Where I can use ReCaptcha?

You can use reCAPTCHA in your HTML page, PHP page, asp.net page even in your WordPress, Joomla, sites. I show you how to use in all platform.

  • Add reCAPTCHA in HTML,PHP page form    

    1. Make a simple form
      <form name=”ajax-form” id=”ajax-form” action=”” method=”post”>
      <input name=”name” id=”name” type=”text” placeholder=”Full Name” />
      <input name=”email” id=”email” type=”text” placeholder=”E-mail” />
      <input name=”contact” type=”text” placeholder=”Contact No.” />
      <textarea name=”comment” id=”message” placeholder=”Write your Comment”></textarea><input class=”send_message” id=”send” type=”submit” /></form>
    2. Now add this before submit button (do not forget to put public key ?)
      <?php  require_once(‘recaptchalib.php);
      $publickey= “”;
      echo recaptcha_get_html($publickey);
      ?>
    3. Put this link in your contact information submission page.
      <?php
      require_once(‘recaptchalib.php‘);
      $privatekey = “”;
      $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 {      //————- HERE IS YOUR CONTACT INFO SUBMISSION CODE    }  ?>
    4. Now all are done test it.
  • Add reCAPTCHA in ASP.Net Page 

  1. Make form in asp.net page
  2. Before form insert this code
    <%@ Register TagPrefix=“recaptcha” Namespace=“Recaptcha” Assembly=“Recaptcha” %>
  3. In form insert this code
      <recaptcha:RecaptchaControl
    ID=“recaptcha”
    runat=“server”
    PublicKey=your_public_key
    PrivateKey=your_private_key
    />
  4. Now your final code look like this
    <%@ Page Language=“VB” %>
    <%@ Register TagPrefix=“recaptcha” Namespace=“Recaptcha” Assembly=“Recaptcha” %>
    <script runat=server%gt;
    Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs)
    If Page.IsValid Then
    lblResult.Text = “You Got It!”
    lblResult.ForeColor = Drawing.Color.Green
    Else
    lblResult.Text = “Incorrect”
    lblResult.ForeColor = Drawing.Color.Red
    End If
    End Sub
    </script>
    <html>
    <body>
    <form runat=“server”>
    <asp:Label Visible=false ID=“lblResult” runat=“server” />
    <recaptcha:RecaptchaControl
    ID=“recaptcha”
    runat=“server”
    Theme=“red”
    PublicKey=your_public_key
    PrivateKey=your_private_key
    />
    <asp:Button ID=“btnSubmit” runat=“server” Text=“Submit” OnClick=btnSubmit_Click />
    </form>
    </body>
    </html>

 

I hope you got it !. I suggest you to every time you make a form or any submission/upload path to your website server you must insert reCAPTCHA in your page.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *