How To php

How to Add Recaptcha in your Website [php]

Written by Aman yadav

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.

A2hosting
Uptime
Features
Support
Overall

Pros

  • Best Support
  • Low Price
  • 100% Uptime
  • Fast Speed Server

Cons

  • No Cons For this

About the author

Aman yadav

Article writer @ Liveurlifehere Blog : I am writing on Top trending article on web,technology-how to,entertainment,top n category post .I am always try to reach you diffrent & good quality content then ever.

Leave a Comment