#!/usr/bin/perl -w
use Fcntl qw(:flock);
use CGI qw(:all escape);
use CGI::Carp qw(fatalsToBrowser);
print header;
$mailprog = '/usr/lib/sendmail';
my $time = scalar(localtime);
# Pick up the submission details:
my @field_names=qw(name email position g-recaptcha-response);
foreach $field_name (@field_names)
{
if (defined param("$field_name"))
{
$FIELD{$field_name} = param("$field_name");
}
}
$captcha=$FIELD{'g-recaptcha-response'};
#Captcha:
# Used to check captcha
use LWP::Simple;
$secretKey = "your key here";
$ip = remote_host;
#print "hello secret= $secretKey";
#print " and response= $captcha";
#print " and remoteip= $ip";
$URL = "https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip;
$contents = get $URL or die;
# contents variable takes the form of: {"success": true, "challenge_ts": "2016-11-21T16:02:41Z", "hostname": "dev2.socialistparty.org.uk"}
# Split contents variable by comma:
my ($success, $challenge_time, $hostname) = split /,/, $contents;
# Split resulting success variable by colon:
my ($success_title, $success_value) = split /:/, $success;
$success_value =~ s/^\s+//;
########################################## captcha success ##################################################
if ($success_value eq "true")
{
your code here if captcha checked
}else{
Fail code here - "you forgot to check the box or you are a robot";
}