homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

php validation to block spam
spam email contact form php

 10:03 pm on Dec 24, 2008 (gmt 0)

I have a contact form set up with php. I'd like to block some robots or users that have been attempting to spam the form. If I create an if statement to block mulitple key words what would it look like? I can get the form to block one word but I'm unsure how to form the if statement to block more than one word:

if ($msg=="insert bad words") {
$error_msg[]='<strong>Go Away!</strong>';

do I separte my target keywords to block with commas or quotes? I've tried everything.



 11:15 pm on Dec 24, 2008 (gmt 0)

Forget about blocking users, too many proxies and dynamic IP

what you need is a clear head :) and review both links and each and every links within both links
Did I already confuse you?

First set [webmasterworld.com]

Second set [webmasterworld.com]


 6:24 am on Dec 25, 2008 (gmt 0)


Is it not a good idea use captcha to avoiod spam?



 4:30 am on Dec 26, 2008 (gmt 0)

henry0 - yep you got me confused.

Mahabub - how come?


 2:04 pm on Dec 26, 2008 (gmt 0)

Blocking bad words can help to keep your form submissions / forums clean, but IMO the majority of spammers posting these bad words are likely to be robots and there are better techniques to try and stop robots, rather than targeting the bad words (there are a lot of bad words!).

Another thread that might be a useful read... Frustrated with Spambots Coming In through Webmail Forms [webmasterworld.com]

Anyway, back to your original query of checking for the existence of any one of a list of words within a block of text. I'm not sure that this can be done within a simple IF statement unless a strpos()-like function exists that can take an array of strings/words to match (which I don't think it can)?

One way to do this is to store your list of bad words in an array, then step through this array searching for each word in your $msg. As soon as you find a $bad_word then fail...

$msg = 'This is my message containing a nasty word.'; 
$bad_words = array('bad','nasty','awful','rude','words');
$found_bad_word = false;
foreach ($bad_words as $word) {
if (strpos($msg,$word) !== false) {
$found_bad_word = true;
if ($found_bad_word) {
echo '<p>Found a bad word: "'.$word.'"</p>';
} else {
echo '<p>No bad words found :)</p>';

As mentioned, I wouldn't use this bad words list to block a user (unless perhaps they persistently offend), but to perhaps warn that they have entered unsavoury content that should be corrected.


 2:14 pm on Dec 26, 2008 (gmt 0)

As per penders, bad words should only be used to clean txt
Banning members does not work perfectly due to proxy and dynamic IP
Captcha is only a better level of defense; be advised that some bots are going through it as butter

penders and I supplied a few links
you should invest time to implement such a system
one of the bots expert on board is alex, review, learn from the posts and seek help when needed.


 2:01 pm on Dec 28, 2008 (gmt 0)

Thanks for the info everyone, I'll take some time and read through those threads.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved