[Gllug] Perl Question - Spam Filter for NMS Form Mail

Henry Gilbert henry.gilbert at gmail.com
Sat Feb 7 11:45:40 UTC 2009


Hi All,

I've finished building an eco-holiday website - and have implemented a
contact form (using NMS Form Mail). But uncustomized the form attracts
a lot of spam!

So I began searching forums and so forth, copying and pasting
"spam-trapping" code without really understanding much about Perl
syntax.

Luckily, it has worked pretty well until now. The spam filter doesn't
require any annoying "Captcha" and has trapped over 99.9% of spam
messages.

So far this is what it does:

- It blocks any messages that contains characters "<" and ">"
- It traps any message from spam-bots silly enough to fill in a hidden
input field.

But this is what I want to do extra:

- Trap any message containing the following sequence of character "://"
- Trap any message that is suspiciously long, say over 1000 characters
in length.

If any of you is proficient in Perl and can help me out with this, I
would be extremely grateful.

Here is the customized code so far:

use CGI;
sub spam {
my $q = new CGI;
my $spamcheck = $q->param('trap') || '';
my $messagecheck = $q->param('message') || '';
if ($spamcheck ne '') {
print "Location: http://www.google.com\n\n";
 exit;
}
elsif ($messagecheck =~ /<(.|\n)*>/) {
print "Location: http://www.google.com\n\n";
 exit;
 }
}
spam();

The NMS Form Mail can be downloaded here: http://nms-cgi.sourceforge.net/

And should you need to inspect the HTML code to the contact form, here
it is: http://www.lucertola.info/contact-form.htm

Thanks for your attention and help,

Henry Gilbert

--
SEO Mastery
http://www.alliancetec.com
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list