homepage Welcome to WebmasterWorld Guest from 54.237.213.31
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
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
brancook

5+ Year Member



 
Msg#: 3814123 posted 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.

 

henry0

WebmasterWorld Senior Member henry0 us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3814123 posted 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]

Mahabub

5+ Year Member



 
Msg#: 3814123 posted 6:24 am on Dec 25, 2008 (gmt 0)

brancook,

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

Thanks
Mahabub

brancook

5+ Year Member



 
Msg#: 3814123 posted 4:30 am on Dec 26, 2008 (gmt 0)

henry0 - yep you got me confused.

Mahabub - how come?

penders

WebmasterWorld Senior Member penders us a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



 
Msg#: 3814123 posted 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;
break;
}
}
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.

henry0

WebmasterWorld Senior Member henry0 us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3814123 posted 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.

brancook

5+ Year Member



 
Msg#: 3814123 posted 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