Jump to content


Photo

Blocking porn / medical entries from Guest Book


  • Please log in to reply
4 replies to this topic

#1 iainlang

iainlang
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 16 June 2006 - 12:37 PM

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();
}
}


#2 deadonarrival

deadonarrival
  • Members
  • PipPipPip
  • Advanced Member
  • 284 posts

Posted 16 June 2006 - 01:37 PM

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

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;
}

DO {
$this->time_warp("Jump to the left","Step to the right","Bend knees in time");
} WHILE (2>1)

Warning: The above post may not make a lot of sense, and the sentence structure will suck. I tend to ramble a lot. Sorry ;-)

#3 iainlang

iainlang
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 16 June 2006 - 08:32 PM

[!--quoteo(post=384553:date=Jun 16 2006, 02:37 PM:name=deadonarrival)--][div class=\'quotetop\']QUOTE(deadonarrival @ Jun 16 2006, 02:37 PM) View Post[/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...

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;
}
[/quote]


[!--quoteo(post=384553:date=Jun 16 2006, 02:37 PM:name=deadonarrival)--][div class=\'quotetop\']QUOTE(deadonarrival @ Jun 16 2006, 02:37 PM) View Post[/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...

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;
}
[/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 ;


#4 JP128

JP128
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationWisconsin

Posted 17 June 2006 - 08:30 AM

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.
}
-----------------------------------------------------------------------
John Ensign - Age 16 - PHP Learner

My email is Johnny.Ensign@gmail.com

#5 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 18 June 2006 - 08:00 PM

[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!!
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users