wxcontact.php with Google reCAPTCHA V2.0 now available

I’ve completed updating a Mike Challis contact script to use Google reCAPTCHA V2.0 for standalone or Saratoga template websites.

See: https://saratoga-weather.org/scripts-contact.php#contact

for details/download. It works in both Saratoga templates and as a standalone.

Nice update :slight_smile:

Awesome, thanks for the update Ken.

Hi Ken. I’m getting an error on my contact page now about the “whos-online” script for some reason.

https://www.northbendweather.com/wxcontact.php



if (($value != '') && (strtolower($value) != 'null') && (strlen(trim($value)) > 0)) {
			return true;
		} else {
			return false;
		}
	}
}                                                                       <<<< Line 358
function db_input($string) {
	return addslashes($string);
}
function db_output($string) {
	return htmlspecialchars($string);


The direct link works fine though. https://www.northbendweather.com/contact-inc.php

The actual error is

Fatal error: Cannot redeclare not_null() (previously declared in /homepages/8/d252567151/htdocs/whos-online/include-whos-online-header.php:922) in /homepages/8/d252567151/htdocs/contact-inc.php on line 358

Since Mike Challis wrote the originals of both scripts, he likely reused some code. In this case, both include-whos-online-header.php and contact-inc.php both have a function named not_null() –

The easy away around that is to rename the not_null() function in contact-inc.php by changing all ‘not_null’ to ‘not_nullX’ in the script… then it should peacefully coexist with your whos-online scripts. You may have to do the same strategy for other functions if they show a fatal error message like that.

PHP doesn’t allow redefinition of a function once declared. It’s why I generally give script-specific names to functions copied from other scripts just to avoid those possible collisions. I’d discontinued use of whos-online on my site quite a while ago, so I’d not seen that error before release of the contact script.

I just made that change and may have opened another can of worms… https://www.northbendweather.com/wxcontact.php

Did you just try the wxcontact.php shipped with the .zip ? That should work fine. It looks like the include() on your current page is trying to include(“wxcontact.php”) not include(“contact-inc.php”). Except for changing the settings area in contact-inc.php (and renaming all the not_null to not_nullX, there shouldn’t be any other changes to that script).

:oops: :oops: #-o #-o

I didn’t look at the script good enough to see that the header, footer, etc were all included and thought I had to use the include_once method into my current script. My bad.

Yes, unlike my other scripts which work standalone first and template aware second, this one was template first, standalone second. That’s why the wxcontact.php page in the distribution just has

<?php
# wxcontact.php for Saratoga templates
/*
Version  2.00 - 07-Apr-2018 rewritten to use Google reCaptcha V2.0 - Ken True - Saratoga-weather.org
*/
  $doStandalone = false; 
	include_once("contact-inc.php");
# end wxcontact.php
?>

since the contact-inc.php has embedded includes for Settings,top,header,menubar and footer at the proper places to produce a template page.

The standalone contact.php has HTML/CSS around a

  $doStandalone = true; 
	include_once("contact-inc.php");

to produce a page without all the embedded template stuff.

Hey Ken,

I uploaded the files to my Saratoga site and configured the variables.

It works without errors but it seems that the email is never sent or goes to lala land.

Is there somewhere that I need to configure email authentication/port to my outbound GoDaddy mail server?

Thanks,
Mort

The script uses the built-in mail() function of PHP … theoretically, that should be set up correctly by your hoster so it just works.

Double check the $mailto setting in the contact-inc.php script. That is where the mail is to go to. It may flow into the Junk/Spam folder of the destination mailbox, so check that too.

No other settings should be needed (than a $mailto variable) for email addressing.

Ken,
Thanks for the update, but… my host does not allow url_fopen :frowning: . I tried pasting in the UVF_fetchUrlWithoutHanging function into the script (from the latest get_UV_forcast_inc.php) and renaming it to GRC_… , but whilst I now get the captcha images and can submit, my mail is not sent and I just get asked to recheck the details of my message and then resubmit. Do you have any ideas on what I can do?
Thanks,
Chris

Hi Chris,
I’d not heard of hosters prohibiting allow_url_fopen before… seems a bit draconian to me.

Please send your modified contact-inc.php to me and I’ll take a look (webmaster at saratoga-weather.org).

It appears that it’s a GoDaddy issue. I’m dreading the tech support call to them.

Ken,
I was about to send you my modified file, but I thought that I would first RFTM to show why my provider prohibited url_fopen and found how to change their default of allow_URL_fopen from off to ON. Low and behold - your original script now works as expected. My bad, sorry for the inconvenience :oops:
Chris

No problem, Chris :slight_smile:

I’m working up a curl-based update anyway (with improved diagnostics) so it will be ready to try when folks have issues again.

Thanks for the update, Ken. :smiley:

Thank you Ken for this update and Thank You for all you do for us weather geeks.