0

I have an email form on my site which has an action to a php page. The php page detects whether the user has entered a name and email, if they haven't it directs them back, if they have it sends an email to me. I want to add a php cussword filter that would prevent the message from being sent if the message contains any words that i want to block out. Does anyone know how i can accomplish this?

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by diafol
0

This is a bit rough, there's probably a better way. But this works.

// Array of blocked words
$bad_words[0] = "badword1";
$bad_words[1] = "badword2";
$bad_words[2] = "badword3";
	
foreach($bad_words as $word) {
	if(strpos(strtolower($email_message), $word) !== false) {
	      // Set flag to check when you exit the loop
              $message_ok = false;
	}
}

if(!$message_ok) {
    // Some code to be executed if a vulgar word is found
}

Edited by Lsmjudoka: n/a

0

If the email is only going to you - what's the problem? Spam? If you're upset by profanity, I bet it's gonna upset the f*** out of you to type in those words which you wanna filter out in the first place.

IF you're worried about automated spam, put a captcha field in your form. Also, have a timeout feature that only allows one post per 15 minutes from a particular IP address. Coz I could send b0ll0ck5 to you, you BUGG3R, and you probably won't pick it up. (Sorry no offence!)

Having the filter won't hurt, but it won't stop all of the brown stuff slopping through the mailbox.

Edited by diafol: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.