Bad word filter

Reply

Join Date: Nov 2008
Posts: 4
Reputation: bigginge is an unknown quantity at this point 
Solved Threads: 0
bigginge bigginge is offline Offline
Newbie Poster

Bad word filter

 
0
  #1
Nov 6th, 2008
I have set up a guestbook on a flash site and the customer has asked for a bad word filter to be incorporated. I have this code for it:
  1. [php]
  2. $bad_words = explode('|', 'badword1|badword2|badword3|etc|etc');
  3. foreach ($bad_words as $naughty)
  4. {
  5. $comments = eregi_replace($naughty, "#!@%*#", $comments);
  6. }
  7. [/php]

Where in the following code should this be inserted, please:
  1. // Part Two - Choose what action to perform
  2. $action = $_GET['action'];
  3.  
  4. switch($action) {
  5. case 'read' :
  6. // Fetch all comments from database table
  7. $sql = 'SELECT * FROM `' . $table . '`';
  8. $allComments = mysql_query($sql, $DBConn) or die("Error in GuestBook Application: " . mysql_error());
  9. $numallComments = mysql_num_rows($allComments);
  10. // Fetch page-wise comments from database table
  11. $sql .= ' ORDER BY `time` DESC LIMIT ' . $_GET['NumLow'] . ', ' . $numComments;
  12. $fewComments = mysql_query($sql, $DBConn) or die("Error in GuestBook Application: " . mysql_error());
  13. $numfewComments = mysql_num_rows($fewComments);
  14. // Generate Output for Flash to Read
  15. print '&totalEntries=' . $numallComments . '&';
  16. print "<br>&entries=";
  17.  
  18. if($numallComments == 0) {
  19. print "No entries in the guestbook, as yet..";
  20. } else {
  21. while ($array = mysql_fetch_array($fewComments)) {
  22. $name = mysql_result($fewComments, $i, 'name');
  23. $email = mysql_result($fewComments, $i, 'email');
  24. $comments = mysql_result($fewComments, $i, 'comments');
  25. $time = mysql_result($fewComments, $i, 'time');
  26.  
  27. print '<b>Name: </b>' . $name . '<br><b>Email: </b>' . $email . '<br><b>Comments: </b>' . $comments . '<br><i>Date: ' . $time . '</i><br><br>';
  28. $i++;
  29. }
  30. }
  31. // Print this only when there aren't any more entries..
  32. if($_GET['NumLow'] > $numallComments) {
  33. print 'No More Entries!&';
  34. }
  35. break;
  36.  
  37. case 'write' :
  38. // Recieve Variables From Flash
  39. $name = ereg_replace("&", "%26", $_POST['yourname']);
  40. $email = ereg_replace("&", "%26", $_POST['youremail']);
  41. $comments = ereg_replace("&", "%26", $_POST['yourcomments']);
  42. $submit = $_POST['submit'];
  43.  
  44. // Current system date in yyyy-mm-dd format
  45. $submitted_on = date ("Y-m-d H:i:s",time());
  46.  
  47. // Check if its submitted from Flash
  48. if($submit == 'Yes'){
  49. // Insert the data into the mysql table
  50. $sql = 'INSERT INTO ' . $table .
  51. ' (`ID`,
  52. `name`,
  53. `email`,
  54. `comments`,
  55. `time`
  56. )
  57. VALUES
  58. (\'\','
  59. . '\'' . $name . '\','
  60. . '\'' . $email . '\','
  61. . '\'' . $comments . '\','
  62. . '\'' . $submitted_on . '\'
  63. )';
  64. $insert = mysql_query($sql, $DBConn) or die("Error in GuestBook Application: " . mysql_error());

Is it after the submit POST [submit] section?
Grateful for any help.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 517
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 82
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro

Re: Bad word filter

 
0
  #2
Nov 6th, 2008
I would assume you want to put this before for insert the data into the database, so withing the write part of the switch before the SQL query.
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 4
Reputation: bigginge is an unknown quantity at this point 
Solved Threads: 0
bigginge bigginge is offline Offline
Newbie Poster

Re: Bad word filter

 
0
  #3
Nov 6th, 2008
Thank you so much. I put it here:
  1. // Print this only when there aren't any more entries..
  2. if($_GET['NumLow'] > $numallComments) {
  3. print 'No More Entries!&';
  4. }
  5. break;
  6.  
  7. case 'write' :
  8. // Recieve Variables From Flash
  9. $name = ereg_replace("&", "%26", $_POST['yourname']);
  10. $email = ereg_replace("&", "%26", $_POST['youremail']);
  11. $comments = ereg_replace("&", "%26", $_POST['yourcomments']);
  12. $submit = $_POST['submit'];
  13. $bad_words = explode('|', 'badword1|badword2|badword3|etc|etc');
  14. foreach ($bad_words as $naughty)
  15. {
  16. $comments = eregi_replace($naughty, "#!@%*#", $comments);
  17. }
  18. // Current system date in yyyy-mm-dd format
  19. $submitted_on = date ("Y-m-d H:i:s",time());
  20.  
  21. // Check if its submitted from Flash
  22. if($submit == 'Yes'){
  23. // Insert the data into the mysql table
  24. $sql = 'INSERT INTO ' . $table .
  25. ' (`ID`,
  26. `name`,
  27. `email`,
  28. `comments`,
  29. `time`
  30. )
  31. VALUES
  32. (\'\','
  33. . '\'' . $name . '\','
  34. . '\'' . $email . '\','
  35. . '\'' . $comments . '\','
  36. . '\'' . $submitted_on . '\'
  37. )';

and it worked a treat. I did alter badword1 etc. with real words. Now just need to sit down and think of the worst words I can.
Marvellous, you're a star.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC