Posted in php
12:45 am, June 25, 2021

verify the google recapture server php

i was still getting quite a bit of spam even after using google recapture v2 and i think this is just as i was using the javascript only version, which disables the submit button if the capture is not solved.

the issue with this is all you need to do is disable javascript and you can still submit the form, so it needs some server side verification to check that the capture is actually solved.

I added this code to the post back on the form to send a check back to google which verifies the capture is solved

I also found that this cases the form to take a while to submit, so it needs some intervention from jquery. As when the form is submitted it has to wait to get the response from google. When its submitted you have to hide the submit button on the form and replace it with a disabled button that has please wait on it. 

here is a demo of its functionality


verify google recapture


<form id="subform" method="post">
	<button type="submit" class="btn btn-success" id="commentButton" disabled="disabled">Register</button>
  	<button class="btn btn-primary hide" disabled="disabled" id="pleaseWait">Please Wait...</button>


	/* hide submit buttons on form clicks */
		$('#subform').on('submit', function(evt) {



// check google recp auth
  $bad_google_cap = "<p class='alert alert-warning'>Recapture Failed</p>";
  if(isset($_POST['g-recaptcha-response'])) {
    $cap_response = $_POST['g-recaptcha-response'];
  } else {
    $page_content .= $bad_google_cap;
  $google_response = file_get_contents("".$cap_response."&remoteip=".$_SERVER['REMOTE_ADDR']);
  $google_response_decoded = json_decode($google_response);
  if(!$google_response_decoded->success === true) {
    $page_content .= $bad_google_cap;
  // check google recp auth

No Items Found.

Add Comment
Type in a Nick Name here
Other Items in php
extract youtube image from video url simple php ip blocker preg replace clean a string only allow a-zA-Z0-9 characters get last month as a number with php verify the google recapture server php rtrim strip white space or strings from the end of a string get the current month as a number show the difference between two dates in years, months, days, hours and seconds counting the occurrence of words in a multidimensional array write string contents to a file with php unable to access the $_FILES when submitting a form php check column exists in table sqlite show all methods or functions in a class (class function version) show all methods (functions) in a class adding an item to an array with php passing in arrays to your functions rather than using variables check server https or http value in php using $_SERVER Remove background image php with image magic get current url with php list a functions variables or arguments php list all the functions in a class php print an array nicely add a toast alert when logging in with half moon dont use md5 for password hashing using password_hash and password_verify php basic page router checking for spam comments function calculate a percentage (dec) difference based on two numbers explode a string into an array using gzdeflate on a string php include tinymce only if a user is logged into the site Quick tool to convert time into decimal generating all css colours with php? php countries array to dropdown form element Fix for Fatal error: Uncaught Error: Call to undefined function file_get_dom() simplehtmldom simple_html_dom Fixing PHP SQLite database is locked warning - Unable to execute statement: database is locked simple usage for php password_hash change string to capital words ucwords change upper case case string to lower case (uppercase, lowercase) convert a string to uppercase with php php substr return part of a string php countries array check if a timestamp is older than one hour making var_dump look nice php mysql table exists function how to display a php file as html with php php convert date now into a sql timestamp Generate a Random User Name return a state name from an australian postcode get the average of a number list using an array in php IP Address
Page Views

This page has been viewed 541 times.

Search Code
Search Code by entering your search text above.

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.


Random Quote
There is no way to happiness. Happiness is the way.