Re: comments function being spammed, how do I stop it?
| From: | Jim Lucas | Date: | Mon, 25 Aug 2008 22:14:01 +0000 |
| Subject: | Re: comments function being spammed, how do I stop it? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-278700@lists.php.net to get a copy of this message | ||
Barnaby Walters wrote:
Hi there! my comments function for my website (at www.waterpigs.co.uk/php/phpTest.php) is being spammed, what would be your sugguestions of a way to deal with it? I was thinking of something to do with searching the strings of comments contained in the database for rude words, etc, but I'm unsure as to how to do it. Any help would be appreciated greatly. Thanks, Barnaby _____________________ www.waterpigs.co.uk barnaby@waterpigs.co.ukHere is the function that I added to a generic guest book script. It works great for me. I have a predefined list of sexual, pharmaceutical, rude, vulgar, etc... words that I have in the spamwords.dat file. function is_spam($str) { $data = './data/spamwords.dat'; $spamword = file($data); $str = strtolower($str); foreach ($spamword AS $word) {
$word = trim($word);
if ( ! empty($word) && // Blank line
strpos($word, 0, 1) != '#' && // Comment line
strpos($str, strtolower($word)) !== false ) { // Compare
return true;
}
}
return false;
}
Just setup the spamwords.dat file to have each word/string that you want to reject for separated on each line.
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare