Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts

    Bad Word filter (Mysql)

    Hello

    Looking for Simple php Script Useing Mysql to store the bad words , and be able to add more direct from the script ..

    I made my Home work Searching but None come up with mysql all store on txt file..

  • #2
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    Try here: http://codingforums.com/post-php-snippet/
    Not tried them (as i would make my own) but the guys on here are good so i trust their work.

  • Users who have thanked Phil Jackson for this post:

    ajloun (08-26-2009)

  • #3
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • Users who have thanked whizard for this post:

    ajloun (08-26-2009)

  • #4
    Regular Coder seco's Avatar
    Join Date
    Nov 2008
    Location
    Oregon
    Posts
    687
    Thanks
    6
    Thanked 79 Times in 77 Posts
    Make a DB
    PHP Code:
    CREATE DATABASE `badword` ;

    CREATE TABLE `badword`.`words` (
    `
    bw_idINT11 NOT NULL AUTO_INCREMENT ,
    `
    wordVARCHAR255 NOT NULL ,
    PRIMARY KEY ( `bw_id` )
    ); 
    Addding to it. add_badword.php
    PHP Code:
    <?php
    if (isset($_POST['submit'])){
     
    // Make a MySQL Connection
     
    mysql_connect("localhost""username""password") or die(mysql_error());
     
    mysql_select_db("badword") or die(mysql_error());
     
     
    //words variable from form
     
    $words $_POST['words'];
     
     
    //inset word
     
    mysql_query("INSERT INTO words (word) VALUES('$words') "
     or die(
    mysql_error());  

     echo 
    "$words Added";
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Add badword</title>
    </head>

    <body>
    <form action="" method="post" name="badword">
    <input name="words" type="text" /><input name="submit" type="submit" value="Add Badword" />
    </form>
    </body>
    </html>

  • Users who have thanked seco for this post:

    ajloun (08-26-2009)

  • #5
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    Thank you All .

    @ seco that exactly wht i'm looking for , but Missing One Thing now is the Censor Function .. the file suppose to filter the world .. Can you make me a Favor and Creat it ..

    @Phil Jackson , whizard ...... I been there .. No mysql .. Seco Got it Right for me
    Last edited by ajloun; 08-26-2009 at 01:13 AM.

  • #6
    Regular Coder seco's Avatar
    Join Date
    Nov 2008
    Location
    Oregon
    Posts
    687
    Thanks
    6
    Thanked 79 Times in 77 Posts
    what are you censoring...a page or a form?

  • Users who have thanked seco for this post:

    ajloun (08-26-2009)

  • #7
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    Post Removed
    Last edited by ajloun; 08-26-2009 at 03:16 AM. Reason: Private code was posted , had to remove it

  • #8
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    the one whizard linked you to (http://www.codingforums.com/showthread.php?t=173314) can easily be modified for mysql. However in it's simplest for assuming you have the mysql tables set up this would work too Censoring messages through PHP
    PHP Code:
    $aString is_string((string)array()) ? true false// true :D 
    [/CENTER]

  • Users who have thanked Zangeel for this post:

    ajloun (08-26-2009)

  • #9
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    Quote Originally Posted by seco View Post
    Make a DB
    you could amke your table like this
    Code:
    CREATE TABLE words
    ( word VARCHAR( 255 ) NOT NULL primary key
    );
    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • Users who have thanked bazz for this post:

    ajloun (08-26-2009)

  • #10
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    Could someone Put it all in One script . the function file , the mysql tabel .. the form .

    well be more clear if someone could make simple message board with this cesor .

    @Zangeel I like Doese Not Mean بهب

    I love = بهب
    I like = ارغب
    there Big Different ..

  • #11
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    Laa young grasshopper, أحب is I love, بهب is simply a visual representation of PHP, transliterated humorously as BHB as the lack of the letter P in the Arabic language.

    Anyway, Go in PHPMYADMIN and run this sql code (make sure to make a database thru cPanel, they have vid tutorials if you don't know how):

    Code:
    CREATE TABLE badword (ID MEDIUMINT NOT NULL AUTO_INCREMENT PRIMARY KEY, swears VARCHAR(60), replace VARCHAR(60))
    Now you have your database, to populate it you do something like this in phpmyadmin:

    Code:
    INSERT INTO badword (`swears`, `replace`) VALUES ('arse', '****');
    INSERT INTO badword (`swears`, `replace`) VALUES ('shiz', '****');
    INSERT INTO badword (`swears`, `replace`) VALUES ('bith', '****');
    Now you have your database setup.

    Now just take a function like I posted in the other post

    PHP Code:
    function wordcensor($txt)
    {

    //REMEMBER to connect to mysql here

        
    $q mysql_query("SELECT `swears`, `replace` FROM `badword`");
        while (
    $row mysql_fetch_array($q))
        {
            
    $txt str_ireplace($row['swears'], $row['replace'], $txt);       
        }
        
        return 
    $txt;

    Now when you're outputting a users string, wrap the function around it like

    PHP Code:
    wordcensor($usersstring); 
    That'll check it for swears.

    Most other questions like if you're new to phpmyadmin, or php mysql coding can be googled but this is the core of it.
    Last edited by Zangeel; 08-26-2009 at 05:56 AM.
    PHP Code:
    $aString is_string((string)array()) ? true false// true :D 
    [/CENTER]

  • Users who have thanked Zangeel for this post:

    ajloun (08-26-2009)

  • #12
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    Ya Not Grasshopper!.. I Got it ... I do Know Phpmyadmin, Mysql and some Php .. But i just Start Learning .. and I have Edited a Module of Making a Comments .. All Done well , But didt know how to intergate Censor word filter to the Module .

    it seem to do it Mysql way Takes Much of Server Resurce , butter Done with Pure Php ..

    So the Quastion now , ? wht if we have a Html Form to send A Comment , No php at all Just Html .. But the process file lets call it post.php Has first the Function of checking the inpute comment if there any bad words from a list of file lets call it badword.txt ..

    lets put this in action.

    1- the Html Form ( as i said no any php only Html ) the file name add.html
    PHP Code:
    <html>

    <
    head>

    <
    title>New Page 1</title>
    </
    head>

    <
    body>

    <
    form method="POST" action="post.php">
      <
    p>
      <
    textarea rows="2" name="S1" cols="20"></textarea></p>
      <
    p><input type="text" name="T1" size="20"><input type="submit" value="Submit" name="B1"></p>
    </
    form>
    <
    p>&nbsp;</p>

    </
    body>

    </
    html
    2- Make the badword.txt file Like
    badword=goodword

    where = Means the badword will be replaced with the word after the =

    3- the Process file Post.php
    PHP Code:
    //Some Censor bad word Function....
    // Check if word found in badword.txt  If found Replace badword with good word 
    // Check if comment  Posted then Send Function 
    Now Can you Do me Something like that , There is Simple way to do all that in javascript .. but Java easy to crack..
    Last edited by ajloun; 08-26-2009 at 06:59 AM.

  • #13
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    The easiest way is just making an array with the badwords and their replacements. My post in the snippit section works with additional options to make sure no ones trying to bypass it. So you can do the same thing like

    Code:
    <html>
    
    <head>
    
    <title>New Page 1</title>
    </head>
    
    <body>
    
    <form method="POST" action="post.php">
      <p>
      <textarea rows="2" name="S1" cols="20"></textarea></p>
      <p><input type="text" name="T1" size="20"><input type="submit" value="Submit" name="B1"></p>
    </form>
    <p>&nbsp;</p>
    
    </body>
    
    </html>
    Then for post.php

    PHP Code:
    //my censoring function, or any other simples ones using an array

    if (isset($_POST))
    {
    echo 
    SmartCensor($_POST['S1']);
    //example if u used my function (links posted here)

    It's really very simple. If you really want a txt file (which i find to be unnecessarily) there's many examples here. Check this out here: Help me censor bad words
    PHP Code:
    $aString is_string((string)array()) ? true false// true :D 
    [/CENTER]

  • Users who have thanked Zangeel for this post:

    ajloun (08-26-2009)

  • #14
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    the Thing that i tried your Script and didt work .. this How the post.php Files look after adding you Code.... where Have i done wrong
    Last edited by ajloun; 08-26-2009 at 12:15 PM.

  • #15
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    Any errors? Does the page show at all?
    PHP Code:
    $aString is_string((string)array()) ? true false// true :D 
    [/CENTER]

  • Users who have thanked Zangeel for this post:

    ajloun (08-26-2009)


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •