Using reCAPTCHA with Perl
Stay organized with collections
Save and categorize content based on your preferences.
Important: Version 1.0 of the reCAPTCHA API is no longer supported, please upgrade to Version 2.0. Learn more
The reCAPTCHA Perl Module provides a simple way to place a CAPTCHA
on your website, helping you stop bots from abusing it. The module wraps the
reCAPTCHA API.
To use reCAPTCHA with Perl, you can download the reCAPTCHA Perl
Module (contributed by Andy Armstrong). You will need to install this module on your
machine (web server). The module depends on the modules LWP::UserAgent
and HTML::Tiny, both of
which will also need to be installed. Here are some basic instructions on installing Perl
modules.
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
Tips and Guidelines
Troubleshooting
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003ereCAPTCHA v1.0 is no longer supported; users should upgrade to v2.0.\u003c/p\u003e\n"],["\u003cp\u003eThe reCAPTCHA Perl Module helps prevent bot abuse on websites by incorporating CAPTCHAs.\u003c/p\u003e\n"],["\u003cp\u003eThis module requires installation along with the LWP::UserAgent and HTML::Tiny modules.\u003c/p\u003e\n"],["\u003cp\u003eImplementation involves client-side code to display the reCAPTCHA widget and server-side code to verify user responses.\u003c/p\u003e\n"],["\u003cp\u003eDetailed instructions and further resources are available for customization, tips, and troubleshooting.\u003c/p\u003e\n"]]],["The reCAPTCHA Perl module enables website integration of CAPTCHAs to prevent bot abuse. It requires downloading and installing the module, along with `LWP::UserAgent` and `HTML::Tiny`. To display the CAPTCHA, use `use Captcha::reCAPTCHA`, create a reCAPTCHA instance, and use the `get_html` method with your public key. Server-side validation involves using `check_answer` with your private key, user IP address, challenge, and response, then checking the validity of the response.\n"],null,["# Using reCAPTCHA with Perl\n\n**Important** : Version 1.0 of the reCAPTCHA API is no longer supported, please upgrade to Version 2.0. [Learn more](/recaptcha/docs/faq)\n\nThe reCAPTCHA Perl Module provides a simple way to place a [CAPTCHA](http://www.google.com/recaptcha/)\non your website, helping you stop bots from abusing it. The module wraps the\n[reCAPTCHA API](/recaptcha/old/intro).\n\nTo use reCAPTCHA with Perl, you can download the [reCAPTCHA Perl\nModule](http://search.cpan.org/dist/Captcha-reCAPTCHA/lib/Captcha/reCAPTCHA.pm) (contributed by Andy Armstrong). You will need to install this module on your\nmachine (web server). The module depends on the modules [LWP::UserAgent](http://search.cpan.org/~gaas/libwww-perl-5.836/lib/LWP/UserAgent.pm)\nand [HTML::Tiny](http://search.cpan.org/dist/HTML-Tiny/lib/HTML/Tiny.pm), both of\nwhich will also need to be installed. Here are some basic [instructions on installing Perl\nmodules](http://www.perlmonks.org/index.pl?node_id=128077).\n\nQuick Start\n-----------\n\nAfter you've signed up for your API keys and downloaded the reCAPTCHA Perl module, below are basic instructions for\ninstalling reCAPTCHA on your site.\n\n### Client Side (How to make the CAPTCHA image show up)\n\nIf you want to use the Perl module to display the reCAPTCHA widget, you'll need to insert\nthis line near the top of the file with the form element where the reCAPTCHA widget will be\ndisplayed: \n\n```css+lasso\n use Captcha::reCAPTCHA;\n```\n\nThen, you need to create an instance of reCAPTCHA: \n\n```perl\n my $c = Captcha::reCAPTCHA-\u003enew;\n```\n\nFinally, to display the reCAPTCHA widget, you must place the following line inside the\n\\\u003cform\\\u003e tag: \n\n```ecl\n print $c-\u003eget_html(\"your_public_key\");\n```\n\nSo, your code may look something like this: \n\n```perl\n use Captcha::reCAPTCHA;\n\n my $c = Captcha::reCAPTCHA-\u003enew;\n\n print \u003c\u003cEOT;\n \u003chtml\u003e\n \u003cbody\u003e\n \u003cform action=\"\" method=\"post\"\u003e\n EOT\n\n print $c-\u003eget_html(\"your_public_key\");\n\n print \u003c\u003cEOT;\n \u003cinput type=\"submit\" value=\"submit\" /\u003e\n \u003c/form\u003e\n \u003c/body\u003e\n \u003c/html\u003e\n EOT\n```\n\nDon't forget to replace `your_public_key` with the value of your\nAPI key.\n\n### Server Side (How to test if the user entered the right answer)\n\nBelow is a skeleton of how to verify the reCAPTCHA answer: \n\n```perl\n use Captcha::reCAPTCHA;\n\n my $c = Captcha::reCAPTCHA-\u003enew;\n\n my $challenge = param 'recaptcha_challenge_field';\n my $response = param 'recaptcha_response_field';\n\n # Verify submission\n my $result = $c-\u003echeck_answer(\n \"your_private_key\", $ENV{'REMOTE_ADDR'},\n $challenge, $response\n );\n\n if ( $result-\u003e{is_valid} ) {\n print \"Yes!\";\n }\n else {\n # Error\n print \"No\";\n }\n```\n\n### Further Reading\n\n- [Customizing Look and Feel](/recaptcha/old/docs/customization)\n- [Tips and Guidelines](/recaptcha/old/docs/tips)\n- [Troubleshooting](/recaptcha/old/docs/troubleshooting)"]]