I got a second server recently and I am migrating a handful of sites off of the old box. Many of them use contact us forms with Google recaptcha v2. They all worked flawlessly on the old box but it seems that the recaptcha test fails on the new server.
Contact us page code:
In the head section ->
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
In thebody secction ->
<form action="https://www.mydomain.com/cgi-bin/contact.cgi" method="post" name="feedback">
...
...
...
<div class="g-recaptcha" data-sitekey="my_local_site_key" data-theme="light" ></div>
</form>
In the contact.cgi ->
sub check_captcha {
use LWP::UserAgent;
$capurl = 'https://www.google.com/recaptcha/api/siteverify';
$capres = $Form{'g-recaptcha-response'};
$capsec = '6LdvyBITAAAAABGfcRNeJY6_ww1h3v9cHi4o66VF';
$capadr = $ENV{'REMOTE_ADDR'};
my $ua = LWP::UserAgent->new();
my $response = $ua->post($capurl, [ 'secret' => $capsec, 'response' => $capres, 'remoteip' => $capadr ]);
if ($response->is_success) {
$capcnt = $response->decoded_content;
$capnum = index($capcnt, 'true');
if ($capnum == -1) {
$validinput = 2048;
return;
} else {
return;
}
} else {
$validinput = 4096;
return;
}
}
On the old box it al worked fine. on the new box the script always returns $valid_input as 4096.
I tried installing the LWP::User Agent module but that did not resolve things.
I do have csf installed on both boxes, disabling csf on the new box has no impact.
Any help/advice would be appreciated.
Contact us page code:
In the head section ->
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
In thebody secction ->
<form action="https://www.mydomain.com/cgi-bin/contact.cgi" method="post" name="feedback">
...
...
...
<div class="g-recaptcha" data-sitekey="my_local_site_key" data-theme="light" ></div>
</form>
In the contact.cgi ->
sub check_captcha {
use LWP::UserAgent;
$capurl = 'https://www.google.com/recaptcha/api/siteverify';
$capres = $Form{'g-recaptcha-response'};
$capsec = '6LdvyBITAAAAABGfcRNeJY6_ww1h3v9cHi4o66VF';
$capadr = $ENV{'REMOTE_ADDR'};
my $ua = LWP::UserAgent->new();
my $response = $ua->post($capurl, [ 'secret' => $capsec, 'response' => $capres, 'remoteip' => $capadr ]);
if ($response->is_success) {
$capcnt = $response->decoded_content;
$capnum = index($capcnt, 'true');
if ($capnum == -1) {
$validinput = 2048;
return;
} else {
return;
}
} else {
$validinput = 4096;
return;
}
}
On the old box it al worked fine. on the new box the script always returns $valid_input as 4096.
I tried installing the LWP::User Agent module but that did not resolve things.
I do have csf installed on both boxes, disabling csf on the new box has no impact.
Any help/advice would be appreciated.
Last edited by a moderator: