Last active
August 29, 2015 14:24
-
-
Save avm99963/9032ca3ce47001ac7433 to your computer and use it in GitHub Desktop.
Recaptcha Demo
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>ReCaptcha Demo</title> | |
<script src="https://www.google.com/recaptcha/api.js" async defer></script> | |
</head> | |
<body> | |
<?php | |
/** Las siguientes variables contienen varias llaves para comunicarse con la API de ReCaptcha. | |
* Las llaves se pueden obtener en: https://www.google.com/recaptcha/admin | |
*/ | |
$sitekey = ""; // Aquí va la site key. | |
$privatekey = ""; // Y aquí la private key. | |
if ($_POST["sent"] == "1") { | |
// Se verifica la respuesta del usuario en el ReCaptcha | |
$response_json = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".urlencode($privatekey)."&response=".urlencode($_POST["g-recaptcha-response"])); | |
$response = json_decode($response_json, true); | |
if ($response["success"] === true) { | |
echo "¡Bien! Has pasado la prueba del ReCaptcha satisfactoriamente \o/"; | |
} else { | |
echo "Parece que eres un robot... Perdóname, pero yo soy de los que discrimina a los robots y no les dejo entrar :-/"; | |
} | |
} else { | |
// Se muestra el recaptcha: | |
?> | |
<form method="POST"> | |
<input type="hidden" name="sent" value="1"> | |
<div class="g-recaptcha" data-sitekey="<?=$sitekey?>"></div> | |
<p><input type="submit" value="Envía"></p> | |
</form> | |
<?php | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment