You are currently browsing the PHP category

Integrate Google New reCaptcha Using PHP

§ March 7th, 2015 § Filed under PHP § Tagged , , , , , , § No Comments

reCAPTCHA is a free service that protects your site from spam and abuse. It uses advanced risk analysis engine to tell humans and bots apart. With the new API, a significant number of your valid human users will pass the reCAPTCHA challenge without having to solve a CAPTCHA. reCAPTCHA comes in the form of a widget that you can easily add to your blog, forum, registration form, etc.

picHundreds of millions of CAPTCHAs are solved by people every day. reCAPTCHA makes positive use of this human effort by channeling the time spent solving CAPTCHAs into digitizing text, annotating images, building machine learning datasets. This in turn helps preserve books, improve maps, and solve hard AI problems.

Get reCaptcha Key
Click here to create a Google reCaptcha application.

Register site
Provide your domain detail without http:// or https:// (e.g for website registration

After registration you will get 2 keys

Site key – This will be used in HTML code

Secret Key – This for communication between your site and Google.


Create Simple Html Form page 

<title>Google reCaptcha</title>
<script src="" async="" defer="defer"></script>
<form action="index.php" method="POST">
<div class="g-recaptcha" data-sitekey="your_site_key"></div>
<input type="submit" value="Submit" />


$errMsg= '';

$curl_init = curl_init();
curl_setopt($curl_init, CURLOPT_URL, $captchaurl);
curl_setopt($curl_init, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_init, CURLOPT_TIMEOUT, 10);
$results = curl_exec($curl_init);

$results= json_decode($results, true);
$errMsg="Valid reCAPTCHA code. You are human.";
$errMsg="Invalid reCAPTCHA code.";
$errMsg="Please re-enter your reCAPTCHA.";