# Using reCAPTCHA with Perl

**Important** : Version 1.0 of the reCAPTCHA API is no longer supported, please upgrade to Version 2.0. [Learn more](https://developers.google.com/recaptcha/docs/faq)

The reCAPTCHA Perl Module provides a simple way to place a [CAPTCHA](http://www.google.com/recaptcha/)
on your website, helping you stop bots from abusing it. The module wraps the
[reCAPTCHA API](https://developers.google.com/recaptcha/old/intro).

To use reCAPTCHA with Perl, you can download the [reCAPTCHA Perl
Module](http://search.cpan.org/dist/Captcha-reCAPTCHA/lib/Captcha/reCAPTCHA.pm) (contributed by Andy Armstrong). You will need to install this module on your
machine (web server). The module depends on the modules [LWP::UserAgent](http://search.cpan.org/~gaas/libwww-perl-5.836/lib/LWP/UserAgent.pm)
and [HTML::Tiny](http://search.cpan.org/dist/HTML-Tiny/lib/HTML/Tiny.pm), both of
which will also need to be installed. Here are some basic [instructions on installing Perl
modules](http://www.perlmonks.org/index.pl?node_id=128077).

## Quick Start

After you've signed up for your API keys and downloaded the reCAPTCHA Perl module, below are basic instructions for
installing reCAPTCHA on your site.

### Client Side (How to make the CAPTCHA image show up)

If you want to use the Perl module to display the reCAPTCHA widget, you'll need to insert
this line near the top of the file with the form element where the reCAPTCHA widget will be
displayed:

```
    use Captcha::reCAPTCHA;
```

Then, you need to create an instance of reCAPTCHA:

```
    my $c = Captcha::reCAPTCHA->new;
```

Finally, to display the reCAPTCHA widget, you must place the following line inside the
\<form\> tag:

```
    print $c->get_html("your_public_key");
```

So, your code may look something like this:

```
    use Captcha::reCAPTCHA;

    my $c = Captcha::reCAPTCHA->new;

    print <<EOT;
    <html>
      <body>
        <form action="" method="post">
    EOT

    print $c->get_html("your_public_key");

    print <<EOT;
        <input type="submit" value="submit" />
        </form>
      </body>
    </html>
    EOT
```

Don't forget to replace `your_public_key` with the value of your
API key.

### Server Side (How to test if the user entered the right answer)

Below is a skeleton of how to verify the reCAPTCHA answer:

```
    use Captcha::reCAPTCHA;

    my $c = Captcha::reCAPTCHA->new;

    my $challenge = param 'recaptcha_challenge_field';
    my $response = param 'recaptcha_response_field';

    # Verify submission
    my $result = $c->check_answer(
        "your_private_key", $ENV{'REMOTE_ADDR'},
        $challenge, $response
    );

    if ( $result->{is_valid} ) {
        print "Yes!";
    }
    else {
        # Error
        print "No";
    }
```

### Further Reading

- [Customizing Look and Feel](https://developers.google.com/recaptcha/old/docs/customization)
- [Tips and Guidelines](https://developers.google.com/recaptcha/old/docs/tips)
- [Troubleshooting](https://developers.google.com/recaptcha/old/docs/troubleshooting)