Created
August 29, 2017 10:58
-
-
Save Mauryashubham/b9f20891fb6d725daabec24514e41b12 to your computer and use it in GitHub Desktop.
Using reCAPTCHA with PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
@author : Shubham Maurya, | |
Email id : [email protected] | |
**/ | |
Hi all , Welcome to shubhammaurya.com , Today we are going to discuss , | |
How to Use google recaptcha in form using PHP | |
LET START | |
So, To start first make a file in notepad and save it as index.php and paste the below code. | |
<?php | |
if(isset($_POST['submit']) && !empty($_POST['submit'])) | |
{ | |
if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) | |
{ | |
//your site secret key | |
$secret = 'Your secret key'; | |
//get verify response data | |
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']); | |
$responseData = json_decode($verifyResponse); | |
if($responseData->success) | |
{ | |
// form submission code goes here | |
} | |
else | |
{ | |
$errMsg = 'Robot verification failed, please try again.'; | |
} | |
} | |
else | |
{ | |
$errMsg = 'Please click on the reCAPTCHA box.'; | |
} | |
} | |
?> | |
<html> | |
<head> | |
<title>reCAPTCHA demo</title> | |
<script src="https://www.google.com/recaptcha/api.js" async defer></script> | |
</head> | |
<body> | |
<form action="?" method="POST"> | |
<div class="g-recaptcha" data-sitekey="your sitekey"></div> | |
<br/> | |
<input type="submit" value="Submit"> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment