Skip to main content

How to use google recaptcha with PHP

How to use google recaptcha with PHP


first sign up here(google recaptcha api).
The key pair consists of a site key and can download recaptcha file from google recaptch php library 


now  you will need to insert this code inside the <form> element where the reCAPTCHA widget will be placed:

  $publickey = "your_public_key"; // you got this from the signup page
  echo recaptcha_get_html($publickey);


    <body> <!-- the body tag is required or the CAPTCHA may not show on some browsers -->
      <!-- your HTML content -->

      <form method="post" action="verify.php">
          $publickey = "your_public_key"; // you got this from the signup page
          echo recaptcha_get_html($publickey);
        <input type="submit" />

      <!-- more of your HTML content -->
Step 3 
NOw you can check response by this code

//first i retrieved the recaptcha coming through post method.
//i have used post method, you can use any method you want.

$recaptcha = $_POST['g-recaptcha-response'];

//After retrieving send a post curl request to verify it.
//you will have to send your secret key along with it.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,"secret=*******************************=".$recaptcha);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
$server_output = json_decode($server_output,true);
curl_close ($ch);

// captacha validated successfully.
// invalid captcha

Popular posts from this blog

How to do PHP unserialize jQuery serialized form data

How to do PHP unserialize jQuery serialized form data

  The Jquery serialize method just takes the form elements and puts them in string form. example - "firstvariable=value&secondvariable=othervalue";
if you are not using associative array then you can access this variable by $_GET and $_POST method.

Example = 
$variable1 = $_GET['firstvariable']; 

but if your data in an array then you need to unserialize jquery serialized data in php. you can unserialize jquery seralized data by usin this methods.

you can unserialize jquery serialize data into php by using parse_str.

$params = array(); parse_str($_GET, $params);//POST METHOD $params = array(); parse_str($_POST, $params);if your data serialize data in a variable then you need to use- $params = array(); parse_str($_POST['formdata'], $params);you can also use this function to unserialize your datafunction unserializeForm($str){ $returndata = array(); $strArray = explode("&",…

Install Cakephp 3+ without composer on localhost

How to Install Cakephp 3 and above on localhost
  you must have xampp installed on your local machine.

Install cakephp 3 and above version on localhost in just 5 steps
Step 1 -- download the letest version cakephp 3 file  zip from here

Step 2 - Unzip this file into
             (xampp/htdocs/newcake)  //newcake is your new folder name

Step 3 - Create a database into mysql
              locate to the localhost/phpmyadmin
              and create a new database with name like (ex - newcake)

Step 4 - Now go to local disk c:/xampp/htdocs/newcake/config/app.php

Step 5 - then go to 228 line and change username password and dbname

ex -       'username' => 'root',  //username is always root for localhost
            'password' => '',   //password is always blank for localhost
            'database' => 'newcake',

  Now open your broswer and navigate to localhost/newcake and you see the default page of cakephp applicati…

Show popup at once Bootstrap Jquery

Show popup at once Bootstrap Jquery
 Sometimes we want to show login signup or welcome popup at once to per user . we can show popup at once to user by using jQuery .
 We can show popup at once with jquery using two methods

 1. localStorage- localStorage is relatively new concept that stores data with no expiration date on client side.
 2. Cookies - Cookies also stores data on client side but the main difference between localStorage and Cookies is that Cookies can manipulated from the server side.

 For our example we are using Bootstrap Modal Popup .to use Bootstrap Modal Popup you should call bootstrap js and css class.

<!-- BootStrap Modal Popup -->
<button type="button" id="btntpr" class="btn btn-info  btn-lg" data-toggle="modal" data-target="#signupnow">Open Modal</button>

<!-- Modal -->
<div id="signupnow" class="modal fade" role="dialog">
  <div class="modal-dialog&quo…