Jump to content

a bad word filter turned on and off per user?


edman78

Recommended Posts

Hello

 

I have a community type website that allows private messages and i want to be able to filter certain words sent in messages.  Their are many bad word filters but all apply to the whole site, i need it to be turned on or off per user.  For example if i have ".com" filtered out every member won't be able to send ".com" in the message and i dont want that.  I want to be able to apply the filter to certain users not the whole site.

 

I plan on charging a fee to upgrade to have the filter turned off that is why i need this.  Is this hard to do? 

Link to comment
Share on other sites

Umm no?

Assume you already have a "rank" field in your database?

if( rank != "freebee" ) {
   echo applyFiltering( $data );
} else {
   echo $data;
}

As long as you got something to differentiate the paying from the non-paying users it's easy as pie, if you don't have a way to do that.. then well, start making a way as it's impossible without.

Link to comment
Share on other sites

Try this for an idea :

 

Presumably you've got a database somewhere with the details of all the users on it.  Add a field to the database, call it something like "filter".

 

The value in this field can be a boolean (true = filter on) or you can set it to a SMALLINT to have differing levels (0 -9 for example) of filtering.

 

Then in your PHP code, when the user logs in, dig out their credentials from the database.  You may (if you so desire) save the value of "filter" in a SESSION variable so you can quickly grab hold of it at any time without having to mess about with the database each time.

 

Now, write a PHP function called something like filtertext(text_input) which strips out any naughty words and returns a text string minus those words

 

Then, all you do is when the user inputs something, test to see if they are filtered or not, and if they are, invoke the function to clean up the text.

 

To turn the filter off, just amend the value in the database table.

 

That's probably not the only way, but its the best I can think of at this hour of night in the UK, hehe  : )

 

Good luck !!

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.