Jump to content

filtering out unwanted words


TGWSE_GY

Recommended Posts

:facewall: :facewall: :facewall: :facewall: :facewall: :facewall: :facewall: :facewall: :facewall:

Hi Guys,

First I want to say yes the language is part of the script to ignore comments with these 7 cuss words in them. However it is still going to my else and adding it to the table and I just want it to stop and go the the defined header location if any of the 7 words are found. Can anyone tell me why its adding to the database?

 

Here is the code:

<?php
include('db_con.php');
$filename = $_POST['filename'];
$comment = $_POST['comment'];
$currentpage = $_POST['currentpage'];
$adminaddress = "http://www.hmtotc.com/private/george/projects/dandj/admin/admin.panel.php";

$shit 			=substr_count($comment, "shit");
$piss 			=substr_count($comment, "piss");
$fuck 			=substr_count($comment, "fuck");
$cunt 			=substr_count($comment, "cunt");
$cocksucker 	=substr_count($comment, "cocksucker");
$motherfucker 	=substr_count($comment, "motherfucker");
	$tits 			=substr_count($comment, "tits");

if ($shit || $piss || $fuck || $cunt || $cocksucker || $motherfucker || $tits){
	header('Location: http://www.hmtotc.com/private/george/projects/dandj/index.php?currentpage=' . $currentpage);
} elseif ($comment === "comment"){
	header('Location: http://www.hmtotc.com/private/george/projects/dandj/index.php?currentpage=' . $currentpage);
} else {
	$imgcommentquery = "INSERT INTO `comments` ( imgname , comments ) VALUES ('$filename', '$comment')";
	mysql_query($imgcommentquery);
	$to = "[email protected]";
	$subject = "New Comments";
	$body = "<p>New Comments have been made please click the link below to allow or delete comments</p><p>$adminaddress</p>";
	mail($to, $subject, $body);
	header('Location: http://www.hmtotc.com/private/george/projects/dandj/index.php?currentpage=' . $currentpage);
}

/*$to = "[email protected]";
$subject = "New Comments";
$body = "<p>New Comments have been made please click the link below to allow or delete comments</p><p>$adminaddress</p>";
mail($to, $subject, $body);
*/

?>

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/170258-filtering-out-unwanted-words/
Share on other sites

A much cleaner method.

<?php
preg_match_all('/(shit|piss|fuck|cunt|cocksucker|motherfucker|tits)/', $comment, $result);
if(count($result[1])) {
// bad words found
print "Rinse your mouth out";
}
else {
// no bad words
print "You are a good boy";
}
?>

Maybe you should try reformatting that if statement try something like

 

if (condition)
  code to be executed if condition is true;
elseif (condition)
  code to be executed if condition is true;
elseif
  code to be executed if condition is false;
else
code to be executed if condition is true; //And so on....

 

Split each of the bad words up with the elseif but hey I am fairly new to this so that's just my 2 cents.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.