use lib '/home/myhomedir/myperllib'; use strict; use warnings; use Captcha::reCAPTCHA; use CGI; # Your reCAPTCHA keys from # https://admin.recaptcha.net/recaptcha/createsite/ my $pubpath = "/home/myhomedir/captcha/public.key"; my $privpath = "/home/myhomedir/captcha/private.key"; open INP,"<$pubpath" or die "Unable to open $pubpath"; my $pubkey = ; chomp $pubkey; close INP; open INP,"<$privpath" or die "Unable to open $privpath"; my $privkey = ; chomp $privkey; close INP; $| = 1; my $q = CGI->new; my $c = Captcha::reCAPTCHA->new; my $error = undef; print "Content-type: text/html\n\n"; print <
EOT # Check response if ( $q->param( 'recaptcha_response_field' ) ) { my $result = $c->check_answer( $privkey, $ENV{'REMOTE_ADDR'}, $q->param( 'recaptcha_challenge_field' ), $q->param( 'recaptcha_response_field' ) ); if ( $result->{is_valid} ) { print "Yes!"; } else { $error = $result->{error}; } } # Generate the form print $c->get_html( $pubkey, $error ); print < EOT print "

The special stuff here

\n"; print < EOT