將 reCAPTCHA 與 Perl 搭配使用
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
重要事項:系統已不再支援 reCAPTCHA API 1.0 版,請升級至 2.0 版。瞭解詳情
reCAPTCHA Perl 模組可讓您輕鬆放置 CAPTCHA
避免漫遊器濫用網站本單元會納入
reCAPTCHA API。
如要將 reCAPTCHA 與 Perl 搭配使用,你可以下載 reCAPTCHA Perl
Module (由 Andy Armstrong 提供)。您必須在自己的
虛擬機器 (網路伺服器)模組依附於 LWP::UserAgent 模組
和 HTML::Tiny,兩者皆包含
您也必須安裝這個應用程式以下是安裝 Perl 的一些基本操作說明
模組。
快速入門
註冊 API 金鑰並下載 reCAPTCHA Perl 模組後,請按照以下基本操作說明
在網站中安裝 reCAPTCHA。
用戶端 (如何讓人機驗證 (Captcha) 圖片顯示)
如要使用 Perl 模組顯示 reCAPTCHA 小工具,請插入
這一行算在檔案頂端附近,表單元素會成為 reCAPTCHA 小工具
顯示:
use Captcha::reCAPTCHA;
接著,您需要建立 reCAPTCHA 執行個體:
my $c = Captcha::reCAPTCHA->new;
最後,如要顯示 reCAPTCHA 小工具,您必須將
<form>標記:
print $c->get_html("your_public_key");
因此,您的程式碼可能如下所示:
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
別忘了將 your_public_key
換成
API 金鑰。
伺服器端 (如何測試使用者是否輸入正確的答案)
以下簡單說明如何驗證 reCAPTCHA 答案:
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";
}
其他資訊
自訂外觀和風格
提示和規範
疑難排解
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-09-09 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2024-09-09 (世界標準時間)。"],[[["reCAPTCHA v1.0 is no longer supported; users should upgrade to v2.0."],["The reCAPTCHA Perl Module helps prevent bot abuse on websites by incorporating CAPTCHAs."],["This module requires installation along with the LWP::UserAgent and HTML::Tiny modules."],["Implementation involves client-side code to display the reCAPTCHA widget and server-side code to verify user responses."],["Detailed instructions and further resources are available for customization, tips, and troubleshooting."]]],["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"]]