Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

i have big problem with filtering bad lang

Status
Not open for further replies.

Al3inguy

Programmer
Nov 15, 2002
8
AE
hi guys i have a chat script and there is a commands call /filter but some trouble makers played with this command they filter the hole page by these words (java, face, color, font .......ect) so can any one tell me how to stop them and also they can filter the text decoration and much more words this is the code


------------------------------

$amer = "size=2 face=\"tahoma\"";

if ($com[1] eq "") {
$err = "*** Sorry, no string provided to be filtered from the public screen!";
}elsif ($com[1] =~ /\~/ || $com[1] =~ /\`/ || $com[1] =~ /\!/ || $com[1] =~ /\@/ || $com[1] =~ /\#/ || $com[1] =~ /\$/ || $com[1] =~ /\%/ || $com[1] =~ /\^/ || $com[1] =~ /\&/ || $com[1] =~ /\*/ || $com[1] =~ /\(/ || $com[1] =~ /\)/ || $com[1] =~ /\-/ || $com[1] =~ /\+/ || $com[1] =~ /\=/ || $com[1] =~ /\}/ || $com[1] =~ /\]/ || $com[1] =~ /\{/ || $com[1] =~ /\[/ || $com[1] =~ /\&quot;/ || $com[1] =~ /\'/ || $com[1] =~ /\:/ || $com[1] =~ /\;/ || $com[1] =~ /\?/ || $com[1] =~ /\// || $com[1] =~ /\>/ || $com[1] =~ /\ava/ || $com[1] =~ /\</ || $com[1] =~ /\,/ || $com[1] =~ /\java/ || $com[1] =~ /color/ || $com[1] =~ /font/ || $com[1] =~ /\\/ || $com[1] =~ /raito/ || $com[1] =~ /\|/){
$err = &quot;*** Invalid filtering: Only aA-zZ, 0-9, and _ characters are allowed in filtering, because some other characters cause some script problems!&quot;;


}else{
open(hhh,&quot;public/$IN{'room'}.txt&quot;);
flock (hhh,2);
@getall = <hhh>;
close(hhh);

open(hhh,&quot;>public/$IN{'room'}.txt&quot;);
flock (hhh,2);
if (length $com[1] >= 3) {
foreach $uff (@getall) {
$x = rindex($uff,$com[1]);
if ($x >= 0) {
push(@thefl,&quot;$uff&quot;);
}else{
print hhh $uff;
}
}
}elsif(length $com[1] < 3 && $IN{'rank'} >= 24 ) {
foreach $uff (@getall) {
$x = rindex($uff,$com[1]);
if ($x >= 0) {
push(@thefl,&quot;$uff&quot;);
}else{
print hhh $uff;
}
}
}else {
foreach $uff (@getall) {
print hhh $uff;
}
$err = &quot;<font $amer>*** 3 or more characters are required to filter ***</font>&quot;
}

if(-e &quot;public_rooms/$IN{'room'}.txt&quot;){
if($data[6] eq $IN{'name'}){
$teltu = &quot;<b>$IN{'name'}</b>&quot;;
}else{
$teltu = &quot;<b>$IN{'name'}</b> ($data[6])&quot;;
}
#open(hhh2,&quot;>>loggers/loggers3.txt&quot;); #### CHANGED FROM loggers3.txt to filtered.txt
open(hhh2,&quot;>>loggers/filtered.txt&quot;);
flock (hhh2,2);
if($thefl[0] ne &quot;&quot;){
print hhh2 &quot;<font $amer color=\&quot;cc33ff\&quot;>**************************************************<br>*** Op $teltu<font color=white size=-3>i</font> filtered the following:</font>&quot;;
foreach $wak(@thefl){
chop($wak);
print hhh2 &quot;<br><font $amer color=\&quot;cc33ff\&quot;>$wak</font>&quot;;
}
print hhh2 &quot;<br><font color=\&quot;cc33ff\&quot;>**************************************************</font>&quot;;
}else{
print hhh2 &quot;<font $amer color=\&quot;cc33ff\&quot;>**************************************************<br>*** Op $teltu<font color=white size=-3>i</font> filtered <i>nothing</i></font><br>&quot;;
print hhh2 &quot;<font $amer color=\&quot;cc33ff\&quot;>**************************************************</font>&quot;;
}
print hhh2 &quot;</font></font></font>\n&quot;;
close(hhh2);
}

open(hhh,&quot;>>public/$IN{'room'}.txt&quot;);
flock (hhh,2);
if (length $com[1] >= 3 || length $com[1] < 3 && $IN{'rank'} >= 24) {
print hhh &quot;<font $amer color=\&quot;000000\&quot;>*** String ($com[1])<font color=white size=-3>i</font> filtered by <b>$IN{'name'}</b><font color=white size=-3>i</font>.</font>\n&quot;;
}
close(hhh);
}
 
Hi i used this method in a guestbook i cant see any reason it wont work for you?

i placed these two bits of code in the config section.

#######################
# words to filter out
# all these words will be found and replaces with the $wordreplace that you set
# you can place as many words as you like here just keep the same format.

@CENSORED=(
'word1','word2','word3');



#######################
# Replace bad words with this
# set this to the word you would like to show instead of the words you want to filter out

$wordreplace = '<i><font color=red><b>&quot;OOPS&quot;</b></font></i>';




This piece of codes needs to go into the script where the form is submitted put it near the beginning of the sub so it replaces the words before it prints them to the text file??


foreach $word (@CENSORED) {
$form{'name'} =~ s/\b$word\b/$wordreplace/gi;
$form{'homepage'} =~ s/\b$word\b/$wordreplace/gi;
$form{'email'} =~ s/\b$word\b/$wordreplace/gi;
$form{'titleofhome'} =~ s/\b$word\b/$wordreplace/gi;
$form{'country'} =~ s/\b$word\b/$wordreplace/gi;
$form{'message'} =~ s/\b$word\b/$wordreplace/gi;
}



I hope this works for you like it worked for me.

Nook6

p.s. im not sure if this is what you need but it does work and it will filter out any words you dont want?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top