Last active
May 4, 2016 16:44
-
-
Save ederrafo/d07cac32cd7d7c3cd7f1c2a9c662ce58 to your computer and use it in GitHub Desktop.
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
/* | |
Version 1. | |
*/ | |
private function validateCaptcha() | |
{ | |
require_once './library/google/1.11/recaptchalib.php'; | |
if (!$_POST["recaptcha_challenge_field"]) { | |
return new View('agency', array("messageFailed" => "formCaptchaErrorMessage")); | |
} | |
$secret = "6LfkVhETAAAAAK0sorKTrEQZVkjowXA2Xmp8MsCr"; | |
$response = null; | |
$response = recaptcha_check_answer($secret, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field'] ); | |
return $response; | |
} | |
/**************************************** | |
v2 | |
****************************************/ | |
view side : | |
<script src='https://www.google.com/recaptcha/api.js?hl=<?php echo L::lang; ?>'></script> | |
<div class="form-group"> | |
<div class="col-sm-3"> | |
<div class="g-recaptcha-response"> | |
</div> | |
</div> | |
<div class="col-sm-8"> | |
<div class="g-recaptcha" data-sitekey="6LfkVhETAAAAAFSqhyycpfcJNrd_UpGyMoiQbrGI"></div> | |
</div> | |
</div> | |
</form> | |
server side: | |
private function validateCaptcha() | |
{ | |
require_once './library/google/recaptchalib.php'; | |
if (!$_POST["g-recaptcha-response"]) { | |
return new View('agency', array("messageFailed" => "formCaptchaErrorMessage")); | |
} | |
$secret = "6LfkVhETAAAAAK0sorKTrEQZVkjowXA2Xmp8MsCr"; | |
$response = null; | |
$reCaptcha = new ReCaptcha($secret); | |
$response = $reCaptcha->verifyResponse($_SERVER["REMOTE_ADDR"], $_POST["g-recaptcha-response"]); | |
return $response | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment