Help searching submitted text
Hi, I have had a problem with bots and spammers writing spam and such into my guestbook. I have decided to have my PHP script do a quick run through of key words and if it finds any, it ignores the submission.
Right now my code
PHP Code:
$subject = $mymessage;
$pattern = "/url/";
if (preg_match($pattern, $subject)) {
// Spam filter found something
$thankyou_block = "This message is considered spam>";
} else {
// Spam filter found nothing so enter it
.....
I can only search for the keyword "url", but I want to ba able to make a list and have it search for any of the words on the list, like "url,link,[/". How do I edit the code to do this. I have searched and searched but have not been able to find anything on the web. Please help.
Re: Help searching submitted text
Unfortunatly mechanisms like yours are easy to circum-navigate. I recommend, that before submitting the post you use image validation. Generating images in PHP uis quite trivial compared to attempting to filter out huge lists of words and potentially produces false positives.
Check out this tutorial: http://www.zend.com/zend/tut/tutorial-mehmet1.php
If you still wnat to go the word search way then I recommend you construct an array of "bad words", loop through the array and search for each word in the string using the stripos() function, or for more powerful matach, (e.g: the word in isolation), use preg_match on each word. To search for a word in isolation you would use a regular expression like this: