Snippet Name: Bad Word Filter
Description: Check a string and filter out prohibited words. Good for forums, guestbooks, etc.
Comment: (none)
Language: PERL
Highlight Mode: PERL
Last Modified: March 05th, 2009
|
#!/usr/bin/perl
#put the badwords in a string separated by a pipe delimiter
$badwords =QQ~phentermine|poker|keno|blackjack|gammon|ringtones|viagra"~;
@check_fields = ("comments", "name", "email");
#my test field values
#$IN{'city'} = qq~my drug is valium ~;
#$IN{'realname'} = qq~i have some lorazepam ~;
&check_badwords;
sub check_badwords {
foreach $check_field (@check_fields) {
$this_field = eval('$'."in{'".$check_field."'}");
if ($this_field =~ m/($badwords)/gi) {
#print qq~found $1 in field '$check_field' \n~;
print qq~Thanks for adding to our Guestbook! \n~;
exit;
}
}
} |