in reply to Re: Perl Captcha Solution
in thread Perl Captcha Solution

Captcha::reCAPTCHA is pure Perl and wouldn't require root access to use a local copy. Just install it into a local user directory and use 'use lib' so that your CGI script will find it.

I haven't found Captcha:reCAPTCHA to be the world's easiest software to use, but it's OK.

This example is derived from one of the posted examples; you may find it useful. Note that I'm assuming that your Captcha::reCAPTCHA library is installed into a local directory, and that you've situated your public and private key files appropriately. Note that for security reasons these key files (especially the private one) shouldn't be located within web-browsable disk space.

HTH ...

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 = <INP>; chomp $pubkey; close INP; open INP,"<$privpath" or die "Unable to open $privpath"; my $privkey = <INP>; 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; <html> <body> <form action="" method="post"> 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; <br/> <input type="submit" value="submit" /> </form> EOT print "<p>The special stuff here</p>\n"; print <<EOT; </body> </html> EOT