matts156 has asked for the wisdom of the Perl Monks concerning the following question:
I have a guestbook that someone has been spamming recently. I simply want to create a list of words in a txt file that can be assigned to a variable. Then when the user clicks submit, it checks to see if the comments field contains any of the blocked words in the list. If so, it simply posts a message saying BLOCKED!!. If not, it allows the user to post.
Here's the code I've been playing with. Someone please have a look at it and tell me where I'm going wrong. I can get it to work if I specify the exact word in quotes where you see "@blocked" below in the IF statement. I've tried various combinations of quotes, using $ instead of @, using "eq" instead of =~, and God knows what else. It either blocks nothing, or blocks everything, regardless of the value of $comments. Here's my flawed code.
# Check for blocked text open (BLOCK,"/home/cowpensv/public_html/cgi-bin/block.txt")|| die "Can +t Open block.txt"; @blocked = <BLOCK>; close (BLOCK); if ( $FORM{'comments'} =~ @blocked ) { print "Content-type: text/html\n\n"; print "<html><head><title>Blocked</title></head>\n"; print "<body><h1>BLOCKED!!</h1>\n"; print "\n</body></html>\n"; exit;}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Blocking based on words in a list
by esskar (Deacon) on Dec 28, 2005 at 00:43 UTC | |
by matts156 (Novice) on Dec 28, 2005 at 01:37 UTC | |
|
Re: Blocking based on words in a list
by moot (Chaplain) on Dec 28, 2005 at 00:50 UTC | |
by VSarkiss (Monsignor) on Dec 28, 2005 at 02:28 UTC | |
by strat (Canon) on Dec 28, 2005 at 08:35 UTC | |
|
Re: Blocking based on words in a list
by myuji (Acolyte) on Dec 28, 2005 at 02:50 UTC | |
|
Re: Blocking based on words in a list
by idsfa (Vicar) on Dec 28, 2005 at 17:19 UTC | |
by esskar (Deacon) on Dec 29, 2005 at 09:21 UTC |