Jump to content

banned word list check on post


BigTime

Recommended Posts

Im wanting to not allow people to post any links in the comments section of a form (spammers) and have created a comma delimited list of essentially of every known domain name extension.

 

To apply the filter I have the following code:

 

$WordAllowed = true;
	$BannedWords = explode(",", ReadDB($Options["ban_words"]));
	if (count($BannedWords)>0) {
	  $checkComment = strtolower($_REQUEST["comment"]);
	  for($i=0;$i<count($BannedWords);$i++){
		  $banWord = trim($BannedWords[$i]);
		  if (trim($BannedWords[$i])<>'') {
			  if(preg_match("/".$banWord."/i", $checkComment)){ 
				  $WordAllowed = false;
				  break;
			  }
		  }
	  }
	}
	if($WordAllowed==false) {
		 $SysMessage =  $OptionsLang["Banned_word_used"]; 
	} else { Insert into my table

 

 

I could have sworn this was working last time I was in this code but recently checking it again it is blocking pretty much everything claiming a banned word is used.  The only thing I can get to post is 'lol'.  Trying funny phrases like: first! or Great information, thanks, this is a test of the comment section, etc....they all get flagged  :'(

 

Can anyone with fresh eyes assist?  Im weary and frustrated and its been forever since I wrapped my head around this. 

 

My banned word list:

www,http,com,org,.aero,.asia,.biz,.com,.coop,.edu,.gov,.info,.int,.jobs,.mil,.mobi,.museum,.name,.net,.org,
.pro,.tel,.travel,.xxx,.a,.bitnet,.ac,.ad,.ae,.af,.ag,.ai,.al,.am,.an,.ao,.aq,.ar,.as,.at,.au,.aw,.az,.ba,.bb,.bd,.be,.bf,.bg
,.bh,.bi,.bj,.bm,.bn,.bo,.br,.bs,.bt,.bv,.bw,.by,.bz,.ca,.cc,.cf,.cg,.ch,.ci,.ck,.cl,.cm,.cn,.co,.com,.cr,.cs,.cu,.cv,.cx,.cy,.cz
,.de,.dj,.dk,.dm,.do,.dz,.ec,.edu,.ee,.eg,.eh,.er,.es,.et,.fi,.fj,.fk,.fm,.fo,.fr,.fx,.ga,.gb,.gd,.ge,.gf,.gh,.gi,.gl,.gm,.gn
,.gov,.gp,.gq,.gr,.gs,.gt,.gu,.gw,.gy,.hk,.hm,.hn,.hr,.ht,.hu,.id,.ie,.il,.in,.io,.iq,.ir,.is,.it,.jm,.jo,.jp,.ke,.kg,.kh,.ki,.km
,.kn,.kp,.kr,.kw,.ky,.kz,.la,.lb,.lc,.li,.lk,.lr,.ls,.lt,.lu,.lv,.ly,.ma,.mc,.md,.mg,.mh,.mil,.mk,.ml,.mm,.mn,.mo,.mp,.mq,.mr,
.ms,.mt,.mu,.mv,.mw,.mx,.my,.mz,.na,.nc,.ne,.net,.nf,.ng,.ni,.nl,.no,.np,.nr,.nt,.nu,.nz,.om,.org,.pa,.pe,.pf,.pg,.ph,
.pk,.pl,.pm,.pn,.pr,.pt,.pw,.py,.qa,.re,.ro,.ru,.rw,.sa,.sb,.sc,.sd,.se,.sg,.sh,.si,.sj,.sk,.sl,.sm,.sn,.so,.sr,.st,.su,.sv,
.sy,.sz,.tc,.td,.tf,.tg,.th,.tj,.tk,.tm,.tn,.to,.tp,.tr,.tt,.tv,.tw,.tz,.ua,.ug,.uk,.um,.us,.uy,.uz,.va,.vc,.ve,.vg,.vi,.vn,.vu,.wf,
.ws,.ye,.yt,.yu,.za,.zm,.zr,.zw

 

Thanks in advance for any help :)

Link to comment
https://forums.phpfreaks.com/topic/237002-banned-word-list-check-on-post/
Share on other sites

hmm I think this is because it is not recognizing the period in the strings, because while I can post mth I can not post mAth and there is a .a extension in the list. 

 

So I guess I need help to insist it includes the dot before the extension.

 

Is this possible?

Your problem is here:

 

if(preg_match("/".$banWord."/i", $checkComment)){ 

 

essentially, you are using "/.at/i" as a regular expression. But the period in a regexp means match anything. To match a period, you have to escape it with a backslash. You should have a look at preg_quote. So your statement would look like this:

 

if(preg_match("/" . preg_quote($banWord, '/') . "/i", $checkComment)){ 

 

 

Archived

This topic is now archived and is closed to further replies.

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