Perl中的ReCaptcha实现

时间:2013-05-22 21:34:43

标签: perl recaptcha

在我的网站上实施recaptcha。 一个选项是谷歌API。但为此我需要使用域名注册才能获得API密钥。 还有其他方法吗?

3 个答案:

答案 0 :(得分:2)

您本身不一定需要域名注册。

他们有一个“全局密钥”的概念,其中一个域密钥将用于多个域。注册时,选择“在所有域上启用此密钥(全局密钥)”选项,并使用唯一标识符(domainkey.abhilasha.com),这样就可以了,您可以使用来自任何域的密钥。

答案 1 :(得分:1)

一种方法:将此代码添加到由html表单调用的perl文件中: 当然简化

my @field_names=qw(name branch email g-recaptcha-response);
foreach $field_name (@field_names)
   {
      if (defined param("$field_name")) 
          {
              $FIELD{$field_name} = param("$field_name");   
}
}

$captcha=$FIELD{'g-recaptcha-response'};

use LWP::Simple;

$secretKey = "put your key here";
$ip = remote_host;
#Remove # rem to test submitted variables are present
#print "secret= $secretKey";
#print " and response= $captcha";
#print " and remoteip= $ip";


$URL = "https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip;
$contents = get $URL or die;

# contents variable takes the form of: "success": true, "challenge_ts": "2016-11-21T16:02:41Z", "hostname": "www.mydomain.org.uk" 
use Data::Dumper qw(Dumper);

# Split contents variable by comma:
my ($success, $challenge_time, $hostname) = split /,/, $contents; 

# Split success variable by colon:
my ($success_title, $success_value) = split /:/, $success; 

#strip whitespace:
$success_value =~ s/^\s+//;

if ($success_value eq "true")
    {

        print "it worked";
    }else{
       print "it did not";
   }

答案 2 :(得分:-3)

如果您只是想阻止垃圾邮件,我更喜欢蜜罐验证码方法:http://haacked.com/archive/2007/09/10/honeypot-captcha.aspx

在表单上放置一个应该留空的输入字段,然后用CSS隐藏它(最好是在外部CSS文件中)。机器人会找到它并将垃圾邮件放入其中,但人类不会看到它。

在表单验证脚本中,检查字段的长度,如果它包含任何字符,请不要处理表单提交。