Skip to main content

Google reCAPTCHA with PHP tutorial

Login to your Google account and submit the form.
Once submit, Google will provide you following two information.
  • Site key
  • Secret key

Integrate it into your website.

To integrate it into your website you need to put it in client side as well as in Server side. In client HTML page you need to integrate this line before <HEAD> tag.

<script src=''></script>
And to show the widget into your form you need to put this below contact form, comment form etc.

<div class="g-recaptcha" data-sitekey="== Your site Key =="></div>
When the form get submit to Server, this script will send ‘g-recaptcha-response’ as a POST data. You need to verify it in order to see whether user has checked the Captcha or not.

Simple comment form with Google reCAPTCH:

    <title>Google recapcha demo - Codeforgeek</title>
    <script src=''></script>
    <h1>Google reCAPTHA Demo</h1>
    <form id="comment_form" action="form.php" method="post">
      <input type="email" placeholder="Type your email" size="40"><br><br>
      <textarea name="comment" rows="8" cols="39"></textarea><br><br>
      <input type="submit" name="submit" value="Post comment"><br><br>
      <div class="g-recaptcha" data-sitekey="=== Your site key ==="></div>
This will generate this form.
Screenshot from 2014-12-05 10:36:46
On server side i am using PHP for now. So on Form submit request we will check the POST variable.

          echo '<h2>Please check the the captcha form.</h2>';
        $response=file_get_contents(" SECRET KEY&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
          echo '<h2>You are spammer ! Get the @$%K out</h2>';
          echo '<h2>Thanks for posting comment.</h2>';

Popular posts from this blog

Draw pyramid shape of stars in PHP using loop structure Write down the code in PHP using loop structure to draw the 3 pyramid shapes of stars as given bellow:


// problem 01 solution
echo  str_repeat('*',$i);
echo "<br />";

echo "<hr />";

// problem 02 solution

echo  str_repeat('*',$i);
echo "<br />";

echo "<hr />";
// problem 03 solution


//echo  str_repeat("&nbsp;",$i-1);
echo  str_repeat('*',$j++);
echo "<br />";

Simple Laravel CRUD with Resource Controllers

Creating, reading, updating, and deleting resources is used in pretty much every application. Laravel helps make the process easy using resource controllers. Resource Controllers can make life much easier and takes advantage of some cool Laravel routing techniques. Today, we'll go through the steps necessary to get a fully functioning CRUD application using resource controllers. For this tutorial, we will go through the process of having an admin panel to create, read, update, and delete (CRUD) a resource. Let's use nerds as our example. We will also make use of Eloquent ORM. This tutorial will walk us through: * Setting up the database and models * Creating the resource controller and its routes * Creating the necessary views * Explaining each method in a resource controller Table of ContentsGetting our Database ReadyEloquent Model for the NerdsCreating the ControllerSetting Up the RoutesThe ViewsMaking It All Work TogetherConclusion To get started, we will need the controll…