Jump to content

Archived

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

iainlang

Blocking porn / medical entries from Guest Book

Recommended Posts

Hello. I am trying to write a code to filter entries (porn and
medical, etc) in my guest book. The words will come in the $comments
field.
The following code is the file that handles the data (including $comments) coming from the guestbook.php
screen. I don't know how to make it work properly. Any help would be
appreciated. Thank you.

// make array of banned words ;
// already entered by operator;
$TableName="banned_words";
$Query="SELECT * FROM $TableName";
$Result=mysql_db_query ($DBName, $Query, $Link);
while ($Row=mysql_fetch_array ($Result))
{
$banned_words[]=$Row[banned_word];
}
$banned_word_count=count($banned_words);

$i=0;
// now loop through the list of banned words ;
for ($i=0; $i<=$banned_word_count; $i++)
{
// to check if the banned word is in the comments ;
// and if it is, junk the entire entry, returning to the ;
// guestbook screen ;
if (strstr($banned_words[$i], $comments) !=0)
{
header("location:guestbook.php");
exit();
}
}

Share this post


Link to post
Share on other sites
Just remembered this in my archive of "could be useful one day" scripts.

I don't think it's exactly what you want, but it might give you some idea of what you want to do. Of course you could also just see if the string contains one of the censored words, and display your error...

[code]function censor ($str) {
// Remove HTML tags.
$str = htmlentities($str);

// Censored words/phrases
$simple_search = array(
  'Naughty pr0n words, copy this line for all your censorings',
  'Naughty pr0n words, copy this line for all your censorings',
  'Naughty pr0n words, copy this line for all your censorings',
);

// Check the words.
$str = preg_replace ($simple_search, "censored", $str);

return $str;
}[/code]

Share this post


Link to post
Share on other sites
[!--quoteo(post=384553:date=Jun 16 2006, 02:37 PM:name=deadonarrival)--][div class=\'quotetop\']QUOTE(deadonarrival @ Jun 16 2006, 02:37 PM) [snapback]384553[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Just remembered this in my archive of "could be useful one day" scripts.

I don't think it's exactly what you want, but it might give you some idea of what you want to do. Of course you could also just see if the string contains one of the censored words, and display your error...

[code]function censor ($str) {
// Remove HTML tags.
$str = htmlentities($str);

// Censored words/phrases
$simple_search = array(
  'Naughty pr0n words, copy this line for all your censorings',
  'Naughty pr0n words, copy this line for all your censorings',
  'Naughty pr0n words, copy this line for all your censorings',
);

// Check the words.
$str = preg_replace ($simple_search, "censored", $str);

return $str;
}[/code]
[/quote]


[!--quoteo(post=384553:date=Jun 16 2006, 02:37 PM:name=deadonarrival)--][div class=\'quotetop\']QUOTE(deadonarrival @ Jun 16 2006, 02:37 PM) [snapback]384553[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Just remembered this in my archive of "could be useful one day" scripts.

I don't think it's exactly what you want, but it might give you some idea of what you want to do. Of course you could also just see if the string contains one of the censored words, and display your error...

[code]function censor ($str) {
// Remove HTML tags.
$str = htmlentities($str);

// Censored words/phrases
$simple_search = array(
  'Naughty pr0n words, copy this line for all your censorings',
  'Naughty pr0n words, copy this line for all your censorings',
  'Naughty pr0n words, copy this line for all your censorings',
);

// Check the words.
$str = preg_replace ($simple_search, "censored", $str);

return $str;
}[/code]
[/quote]

You're right - it's not what I want. I don't want to replace anything; as my original post said -
// to check if the banned word is in the comments ;
// and if it is, junk the entire entry, returning to the ;
// guestbook screen ;

Share this post


Link to post
Share on other sites
You could use something like this.
You would need to put the $comment (all of its words) into an array. then have $badwords in an array and check to see if any of those words match... I know it can be done, because I had a forum page once that I got from open source, and that is what it did.. I am very bad with arrays, and loops, something maybe I should try getting better at... But if you know what I am saying, then maybe this helped you.


if(ereg($badwordArray, $commentArray)){
//redirect to page.
} else {
//post to comments.
}

Share this post


Link to post
Share on other sites
[a href=\"http://www.imarc.net/blog/61/stopping_blog_comment_spam_with_php/\" target=\"_blank\"]http://www.imarc.net/blog/61/stopping_blog..._spam_with_php/[/a]

That's just what you want. Enjoy!!

Share this post


Link to post
Share on other sites

×

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.