add Google No CAPTCHA google reCAPTCHA PHP

how to add Google No CAPTCHA google reCAPTCHA PHP

In this post i will show you how to add Google No CAPTCHA google reCAPTCHA using php. it is very safe way to protect your site with robot user.

How to register for Google No CAPTCHA
Step 1 :-

First, we have to create API key, so we have to go https://www.google.com/recaptcha/admin create. Add label and domain register site in google recaptcha admin.

 

add label and domain register site in google recaptcha admin.
dd label and domain register site in google recaptcha admin.

Step 2 :-

We get key and its partner secret key ::

key and its partner secret key
key and its partner secret key

Step 3 :-

Add your recaptcha key of google api.js ::

<!-- recaptcha js script -->
<script src='https://www.google.com/recaptcha/api.js'></script>

Step 4 :-

Add this site key in div data-sitekey="add-hear"


<div class="g-recaptcha" data-sitekey="add-your-data-site-key"></div>;

Code For reCAPTCHA in php

In this post we will show how to add Google reCAPTCHA in you web site. It is very easy and sefe way to prove they are human not robot.

no-captcha-recaptcha
no-captcha-recaptcha

In this post we will show you how to use register your domain for Google reCAPTCHA and how to get site key and secret key.

Registering and Retrieving Keys for reCAPTCHA

All instraction for register your site Google No CAPTCHA reCAPTCHA.

Google No CAPTCHA reCAPTCHA PHP Code Example

<!doctype html>
<html>
    <head>
        <title>googles recaptcha php code example | onlinecode</title>
		<!-- js recaptcha api call -->
		<script src='https://www.google.com/recaptcha/api.js'></script>        
    </head>
    <body>
	<form method="post" action="index.php">
		<!-- add your data site key in div tag -->
		<div class="g-recaptcha" data-sitekey="your-data-site-key"></div>
        <input type="submit" value="Submit" class="btn btn-primary submit" name="submit" />
    </form>
	<!-- end form -->
    </body>
</html>

<?php 
// check for post method call. 
if($_SERVER["REQUEST_METHOD"] === "POST") 
{ 
	//verify captcha code process 
	// add your secret key 
	$google_recaptcha_secret = "your-data-secret-key"; 
	
	// pass secret key in google recaptcha api url 
	$api_response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$google_recaptcha_secret."&response=".$_POST['g-recaptcha-response']); 
	
	// json decode for data 
	$api_response = json_decode($api_response, true); 
	
	if($api_response["success"] === true) 
	{ 
		// success result 
		echo "Logged In Successfully"; 
	} 
	else 
	{ 
		// not success result 
		echo "You are a robot"; 
	} 
} 
?>

View Demodownload

Leave a Comment

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

3  +  2  =  

We accept paid advance and paid guest Posting on our Site : Contact US