User Tools

Site Tools


Translations of this page:

Sidebar

Documentation index

google_recaptcha

Google ReCaptcha

It's a great way to skip a regular captcha

Here's how to implement it

1. Open https://developers.google.com/recaptcha, register and get 2 keys

Recaptcha V3 Site key 	
Recaptcha V3 Secret key

2. Add those codes to Rotation - Settings - Social and switch to “Use Captcha on Comments?” in Rotation - Settings

Recaptcha for comments

Google adds a small JS code and checks if a current surfer is a bot, then it adds the result of the check to appointed field

Here's an example for comments (gallery page)

  <head>
    <title> <!--GALLERY_SLUG--> with reCAPTCHA</title>
     <script src="https://www.google.com/recaptcha/api.js?render=<!--TUBE_RECAPTCHA_SITE_KEY-->"></script>

<script>
function CheckRecaptcha() {
grecaptcha.ready(function() {
    grecaptcha.execute('<!--TUBE_RECAPTCHA_SITE_KEY-->', {action: 'report_form'}).then(function(token) {
       document.add_comment.recaptcha.value = token;
       document.add_comment.submit();
    });
});
}
</script>

take a look at those tags <!–TUBE_RECAPTCHA_SITE_KEY–>, this is Recaptcha V3 Site key (ie public key)

comments form


<? if ('<!--ERROR-->' != 'OK') echo "error: <!--ERROR-->"; ?>

<FORM name="add_comment" method="POST">
<input type="hidden" name="action" value="add_comment">
<input type="hidden" name="recaptcha" id="recaptcha" value=""> (google adds the result of the check here)

<label>Name:</label> <input class="s_input" type="text" name='username' id='username' value="<?=$user['username']?>">
<br>

 <textarea class="s_text" class="ph2" name='comment' id='comment' rows=5 cols=35 value="Leave Your Comments Here"></textarea>

<input type=button value='Send comment' onClick=CheckRecaptcha()> (note that type=button so we check google status bufore submit )
</form>

Recaptcha Anticheat

There's a good way to check traffic with google, ie you'll get what amount of traffic Google mark as bot traffic

At any page (in most cases that would be an index page) you have to add

<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://www.google.com/recaptcha/api.js?render=<!--TUBE_RECAPTCHA_SITE_KEY-->"></script>

<script>
req_flag = false;
recaptcha_code = '';


if ('<!--RECAPTCHA_MAX_RATE-->') {
    if (Math.random() > '<!--RECAPTCHA_MAX_RATE-->') req_flag = true;
}


grecaptcha.ready(function() {
    grecaptcha.execute('<!--TUBE_RECAPTCHA_SITE_KEY-->', {action: 'index_page'}).then(function(token) {
       recaptcha_code = token;
    });
});


$(document).ready(function(){
	$('.gallery_link').each(function() {
		$(this).click(function(){
		    if (req_flag || recaptcha_code === '') return;
		    req_flag = true;

        	$.post('/',
	        {
                'action': 'check_recaptcha',
                'recaptcha_code': recaptcha_code,
    	    },
	        function (data) {
	  	        
	        }
	        );
		    
		});
	});


});



</script>

you have to add “class='gallery_link' ” to each link at that page, here's an example

<thumb num=1-10>
<a class='gallery_link' href='/gallery/<!--GALLERY_SLUG-->/index.html'> <!--GALLERY_ID--> </a> <br>
</thumb>

Of course you can replace gallery_link, the idea is to call Google JS each time a user clicks a link

Then you have to go to Settings - layouts and add a column Google Recaptcha

That's it, in an hour take a look at the column Google Recaptcha in trade screen

PS Note that free amount is 1300 hits \ hour so we dont check each hit, but a part of it (RECAPTCHA_MAX_RATE), but if you are ready to pay Google for more - you can remove RECAPTCHA_MAX_RATE (contact support if you have issues removing this parameter)

google_recaptcha.txt · Last modified: 2023/01/09 04:02 by admin