Jump to content

Blocking porn / medical entries from Guest Book


iainlang

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();
}
}
Link to comment
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]
Link to comment
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 ;
Link to comment
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.
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.