Difference between revisions of "Google NoCaptcha"
From KOP KB
Line 10: | Line 10: | ||
<syntaxhighlight lang="html4strict"> | <syntaxhighlight lang="html4strict"> | ||
<div class="g-recaptcha" data-sitekey="yourpublickey" data-theme="dark" ></div> | <div class="g-recaptcha" data-sitekey="yourpublickey" data-theme="dark" ></div> | ||
+ | </syntaxhighlight> | ||
+ | = PHP Verfication= | ||
+ | Below is the php verification code using your secret key | ||
+ | <syntaxhighlight lang="php"> | ||
+ | $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>"; | ||
+ | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 14:43, 29 March 2016
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>";
}