reCAPTCHA V2.0 Perl example anyone?

805 views
Skip to first unread message

Manfred Drechsel

unread,
Aug 13, 2015, 10:19:31 AM8/13/15
to reCAPTCHA
Hi,

I already portet successfully the PHP parts from my site from reCAPTCHA 1.0 to 2.0. Still left are the Perl parts (aktually just the verification of the user response). Anyone a Perl example for that?

Thanks
Manfred

pete mason

unread,
Nov 23, 2016, 7:27:12 AM11/23/16
to reCAPTCHA
#!/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";

}
 

Manfred Drechsel

unread,
Nov 23, 2016, 4:08:23 PM11/23/16
to reCAPTCHA
Thanks for your reply, but I've figured it out and got it working since December 2015. Nobody seemed to be interested in V2 & Perl.

Anyway, thanks again
Manfred
Reply all
Reply to author
Forward
0 new messages