I have used this script in many successful matched searches and bot rejections. However, attempts to use it to reject a TLD in a message field has failed.
Successful example that rejects "bitcoin" if it shows up in the "Message" field of my form that relies on a perl form script I have modified is as follows:
use CGI;
sub bottle17 {
my $q = new CGI;
my $botcheck17 = $q->param('Message') || '';
if ($botcheck17 =~ m/bitcoin/) {
print "Location: http://www.edwardgpalmer.com/A301_error.html\n\n";
exit;
}
}
bottle17();
I've used the above code to eliminate threats in my forms from 21 websites. I am now getting some other spam and I'd like to expand on this code concept. However, I am NOT a Perl programmer. I am a web developer who tinkers with Perl and have been successful.
This code and others like it attempting to use a period to effectively reject a TLD found in a field has me stumped. It appears that Perl does not like the use of a period before a match code. Example
use CGI;
sub bottle17 {
my $q = new CGI;
my $botcheck17 = $q->param('Message') || '';
if ($botcheck17 =~ m/.com/) {
print "Location: http://www.edwardgpalmer.com/A301_error.html\n\n";
exit;
}
}
bottle17();
In this illustration, the error message would pop up whenever the word com was used in the message field. Of course, my objective would be to reject the TLD .com if it showed up in this field.
Another example would be ...
use CGI;
sub bottle17 {
my $q = new CGI;
my $botcheck17 = $q->param('email') || '';
if ($botcheck17 =~ m/.ru/) {
print "Location: http://www.edwardgpalmer.com/A301_error.html\n\n";
exit;
}
}
bottle17();
My objective in this case would be to reject all form mail from a Russian TLD .ru. However, in both of the above cases the period is ignored. In this illustration, any email that contains the letters ru would be rejected.
I'm wondering what a code work around to reject a TLD in a form field would be.
I've got two days hunting on this subject, which I thought was working. ha ha
It's not!
This type of code has been very effective in rejecting various spammers on my form pages. Any answers on working around the period in Perl to effect a .com reject or .ru TLD reject would be appreciated.
Thanks Ed
CodePudding user response:
There is a lot of text in this question, but it all boils down to a very basic misunderstanding: the =~
operator doesn't match substrings it matches patterns. Specifically patterns called "regexes"; search for that term and you'll find thousands of tutorials with the details.
In a regex, letters match themselves, which is why /bitcoin/
matches the string "bitcoin". But other characters have other meanings, and .
stands for "any character". To match a literal .
you have to "escape" it as \.
A regex also matches anywhere in the string by default (again, that's why /bitcoin/
works), but you want it to match at the end. You do that with the $
character in the pattern, so:
/\.ru$/
CodePudding user response:
Thanks for the input. I resolved the issue using the following exammple
=~ m/.com$/
Another lesson on the period and escape characters.