Difference between revisions of "FormMail Captcha"

From KOP KB
Jump to: navigation, search
(Created page with "== Referrers and Recipients == <syntaxhighlight lang="perl"> #whatever domains they decided to use should go in referrers. @referers = ('www.domain.com','domain.com'); # @re...")
 
(Referrers and Recipients)
Line 1: Line 1:
 
== Referrers and Recipients ==
 
== Referrers and Recipients ==
 
+
Make sure the customer has this set up properly as well
 
<syntaxhighlight lang="perl">
 
<syntaxhighlight lang="perl">
 
#whatever domains they decided to use should go in referrers.
 
#whatever domains they decided to use should go in referrers.
Line 11: Line 11:
 
# If we are troubleshooting the receiving make sure this has a string of the email and not a variable #
 
# If we are troubleshooting the receiving make sure this has a string of the email and not a variable #
 
@recipients = '[email protected]';
 
@recipients = '[email protected]';
 +
</syntaxhighlight>
 +
 +
==  Use LWP ==
 +
This will need to be put just before it shows all the &check's down the page
 +
<syntaxhighlight lang="perl">
 +
use LWP::UserAgent;
 +
</syntaxhighlight>
 +
== Calling the Check Captcha ==
 +
<syntaxhighlight lang="perl">
 +
# Check the captcha challenge and response.
 +
&check_captcha;
 +
</syntaxhighlight>
 +
== Checking the Captcha ==
 +
<syntaxhighlight lang="perl">
 +
##############################################################################
 +
# Check the CAPTCHA response via the reCAPTCHA service.
 +
sub check_captcha {
 +
 +
      my $ua = LWP::UserAgent->new();
 +
    my $result=$ua->post(
 +
    'http://www.google.com/recaptcha/api/verify',
 +
      {
 +
          privatekey => '6LfMzPwSAAAAAL8zk68BvstQisi_AIhhCc3hnmTN',
 +
          remoteip  => $ENV{'REMOTE_ADDR'},
 +
          challenge  => $Form{'recaptcha_challenge_field'},
 +
          response  => $Form{'recaptcha_response_field'}
 +
      });
 +
 +
      if ( $result->is_success && $result->content =~ /^true/) {
 +
              return;
 +
      } else {
 +
              &error('captcha_failed');
 +
      }
 +
}
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 23:59, 28 October 2014

Referrers and Recipients

Make sure the customer has this set up properly as well

#whatever domains they decided to use should go in referrers.
@referers = ('www.domain.com','domain.com');

# @recipients defines the e-mail addresses or domain names that e-mail can   #
# be sent to.  This must be filled in correctly to prevent SPAM and allow    #
# valid addresses to receive e-mail.  Read the documentation to find out how #
# this variable works!!!  It is EXTREMELY IMPORTANT.                         #
# If we are troubleshooting the receiving make sure this has a string of the email and not a variable #
@recipients = '[email protected]';

Use LWP

This will need to be put just before it shows all the &check's down the page

use LWP::UserAgent;

Calling the Check Captcha

# Check the captcha challenge and response.
&check_captcha;

Checking the Captcha

##############################################################################
# Check the CAPTCHA response via the reCAPTCHA service.
sub check_captcha {
 
      my $ua = LWP::UserAgent->new();
     my $result=$ua->post(
     'http://www.google.com/recaptcha/api/verify',
      {
          privatekey => '6LfMzPwSAAAAAL8zk68BvstQisi_AIhhCc3hnmTN',
          remoteip   => $ENV{'REMOTE_ADDR'},
          challenge  => $Form{'recaptcha_challenge_field'},
          response   => $Form{'recaptcha_response_field'}
      });

      if ( $result->is_success && $result->content =~ /^true/) {
              return;
      } else {
              &error('captcha_failed');
      }
}