iainlang Posted June 16, 2006 Share Posted June 16, 2006 Hello. I am trying to write a code to filter entries (porn andmedical, etc) in my guest book. The words will come in the $commentsfield.The following code is the file that handles the data (including $comments) coming from the guestbook.phpscreen. I don't know how to make it work properly. Any help would beappreciated. 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(); }} Quote Link to comment https://forums.phpfreaks.com/topic/12148-blocking-porn-medical-entries-from-guest-book/ Share on other sites More sharing options...
deadonarrival Posted June 16, 2006 Share Posted June 16, 2006 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 Link to comment https://forums.phpfreaks.com/topic/12148-blocking-porn-medical-entries-from-guest-book/#findComment-46256 Share on other sites More sharing options...
iainlang Posted June 16, 2006 Author Share Posted June 16, 2006 [!--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 ; Quote Link to comment https://forums.phpfreaks.com/topic/12148-blocking-porn-medical-entries-from-guest-book/#findComment-46437 Share on other sites More sharing options...
JP128 Posted June 17, 2006 Share Posted June 17, 2006 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.} Quote Link to comment https://forums.phpfreaks.com/topic/12148-blocking-porn-medical-entries-from-guest-book/#findComment-46599 Share on other sites More sharing options...
AndyB Posted June 18, 2006 Share Posted June 18, 2006 [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!! Quote Link to comment https://forums.phpfreaks.com/topic/12148-blocking-porn-medical-entries-from-guest-book/#findComment-47083 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.