Skip to content

Instantly share code, notes, and snippets.

@pipiscrew
Created October 18, 2017 17:36
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 pipiscrew/08a3e430a5a0060beeaafc423dfa611b to your computer and use it in GitHub Desktop.
Save pipiscrew/08a3e430a5a0060beeaafc423dfa611b to your computer and use it in GitHub Desktop.
Recaptcha Landing Page Demo - Avoid Bots
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width; initial-scale=1.0;">
<title>Recaptcha Landing Page Demo - Avoid Bots</title>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
var validate = function(gResponse){
jQuery.ajax({
url: '/recaptcha/',
type: 'POST',
dataType: 'json',
data: {
response: gResponse
},
success: function(r){
if (!!r.success) {
var d = new Date(r.cookie_timestamp * 1000);
var expires = "; expires="+d.toGMTString();
document.cookie = "botverification="+r.cookie_timestamp+":"+r.cookie_hmac+expires+"; path=/";
location.reload();
}
},
error: function(){
grecaptcha.reset();
}
});
};
var execGoogleInvisibleRecaptcha = function() {
var holderId = grecaptcha.render("g-recaptcha",{
'sitekey': 'x',
'size': 'invisible',
'badge': 'bottomright'
}, true);
grecaptcha.execute(holderId);
// Poison body
$('body').click(function(evt){ grecaptcha.execute(holderId); });
}
</script>
<style>
body, html, p { margin: 0; padding: 0; }
.container { max-width: 960px; text-align: center; padding: 22px 0 0; margin: 0 auto }
.container > p { font: normal 18px/22px Arial,Geneva,Tahoma,sans-serif; padding: 0 0 16px; }
.container > p + p { color: #999 }
.g-recaptcha { display: inline-block; margin: 0 auto; position: fixed; bottom:0%; }
</style>
</head>
<body>
<div class="container">
<p>Due to the increased activity of the unwanted bots from foreign IP addresses.</p>
</div>
<div id="g-recaptcha" class="g-recaptcha" data-callback="validate"></div>
<script src="https://www.google.com/recaptcha/api.js?onload=execGoogleInvisibleRecaptcha&render=explicit" async defer></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment