Skip to content

Instantly share code, notes, and snippets.

@xexu
Created November 20, 2018 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xexu/c94bbfc204f96f7b2a98d9e7acc83241 to your computer and use it in GitHub Desktop.
Save xexu/c94bbfc204f96f7b2a98d9e7acc83241 to your computer and use it in GitHub Desktop.
<?php
require_once "vendor/autoload.php";
$secret = 'GQ3e7zjLwXUtftQJMGBbARQ85tVTkHHSx72XaBB3';
if (isset($_POST["name"]) && $_POST["name"]) {
$gRecaptchaResponse = isset($_POST["g-recaptcha-response"])? $_POST["g-recaptcha-response"] : null;
$recaptcha = new \ReCaptcha\ReCaptcha($secret);
$resp = $recaptcha->verify($gRecaptchaResponse, $_SERVER['REMOTE_ADDR']);
if ($resp->isSuccess()) {
die("Enhorabuena, eres un humano!");
} else {
die("beep bop!");
}
}
if (isset($_POST["email"]) && $_POST["email"]) {
$gRecaptchaResponse = isset($_POST["g-recaptcha-response"])? $_POST["g-recaptcha-response"] : null;
$recaptcha = new \ReCaptcha\ReCaptcha($secret);
$resp = $recaptcha->verify($gRecaptchaResponse, $_SERVER['REMOTE_ADDR']);
if ($resp->isSuccess()) {
die("Enhorabuena, eres un humano!");
} else {
die("beep bop!");
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Ejemplo Invisible reCAPTCHA acceseo.com</title>
<script src='https://www.google.com/recaptcha/api.js'></script>
<script>
function onSubmit(token) {
document.getElementById("demo-form").submit();
}
function onSubmitEmail(token) {
document.getElementById("demo-form-email").submit();
}
</script>
</head>
<body>
<form id="demo-form" action="index.php" method="post">
<label>Nombre <input type="text" id="name" name="name" /></label>
<input type="submit" class="g-recaptcha" data-sitekey="a7axuLvFzsEssDtgRYTCpfXbB5seGdRnaERUJHWS" data-callback="onSubmit"/>
</form>
<hr>
<form id="demo-form-email" action="index.php" method="post">
<label>Email <input type="text" id="email" name="email" /></label>
<input type="submit" class="g-recaptcha" data-sitekey="a7axuLvFzsEssDtgRYTCpfXbB5seGdRnaERUJHWS" data-callback="onSubmitEmail"/>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment