Google NoCaptcha

From KOP KB
Jump to: navigation, search

Header Code

At the top of the page you will want this code in the header tag somewhere.

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

The Div

The div below you will try to put as near to the submit button as you want.

<div class="g-recaptcha" data-sitekey="yourpublickey" data-theme="dark" ></div>

PHP Verfication

Below is the php verification code using your secret key

$secret="yoursecretkey";
$response=$_POST["g-recaptcha-response"];
$verify=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$secret}&response={$response}");
$captcha_success=json_decode($verify);

if ($captcha_success->success==false) {
	echo "<p>Please try again <a href='https://www.domain.com/backtoformpagename.php'>Click here</a></p>";
}
else if ($captcha_success->success==true) {
	
    // send mail
    mail("[email protected]",$subject,$message);
	
	echo "<p>Thank you message.</p>";
}