#!/home/ben/software/install/bin/perl use warnings; use strict; use CGI; use LWP::UserAgent; use JSON::Parse 'parse_json'; my $secret = 'ThisIsNotARealOne'; my $gurl = 'https://www.google.com/recaptcha/api/siteverify'; my $cgi = CGI->new (); if (! check_captcha ($cgi)) { # OK } sub check_captcha { my ($icgi) = @_; my $ua = LWP::UserAgent->new (); my $response = $cgi->param ('g-recaptcha-response'); my $remoteip = $ENV{REMOTE_ADDR}; my $greply = $ua->post ( $gurl, { remoteip => $remoteip, response => $response, secret => $secret, }, ); if ($greply->is_success ()) { my $json = $greply->decoded_content (); my $out = parse_json ($json); if ($out->{success}) { return undef; } return $json; } return "Connection to reCAPTCHA failed"; }