Closed Thread Icon

Topic awaiting preservation: Language filter (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12568" title="Pages that link to Topic awaiting preservation: Language filter (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Language filter <span class="small">(Page 1 of 1)</span>\

 
The Jackal
Paranoid (IV) Inmate

From: The Dark Side of the Moon
Insane since: Jun 2000

posted posted 01-05-2003 09:39

Hey there. I have a quiz generator on a site for a client and I need some help. The Quiz generator is Quirex (found at http://www.teca-scripts.com/free/quirex.php). The problem is that some people have been using foul language when they enter thier name in the form. Is there any way I can add a mini filter to prevent certain words from being used in the form? The line of code that inserts the 'Name' section of the form reads as follows:

print "Name: <input type=text name=name size=20 maxlength=40> ";

Any help would be great. Thanks.

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 01-05-2003 12:34

you're using php, right?

Well, there are two options: you either overwrite the foul words with something along the lines of #@#@, or you deny using them (in that case you'd have to die() the page, present a nice error message and the like).
Anyhow, here's the code for replacing for certain words

code:
$words = array( 
"evil word", //obviously replace this with the words you want to detect
"foul word",
);
//asuming your text is called $text
$text = preg_replace($words,'@#$)',$text);




Hoping to have helped,

Tyberius Prime

The Jackal
Paranoid (IV) Inmate

From: The Dark Side of the Moon
Insane since: Jun 2000

posted posted 01-06-2003 04:47

It is actually a CGI script. It calls on a file called 'showquiz.pl' to give the form to where you enter your name. Exactly how do I add this code to the form? I tried a couple ways, but I keep getting a 500 error. What am I doing wrong? I tried it like this:

print "Name: <input type=text name=name size=20 maxlength=40>
$words = array( "evil word", //obviously replace this with the words you want to detect"foul word",);
//asuming your text is called $text
$text = preg_replace($words,'@#$)',$text)";

The original looked like this:

print "<tr bgcolor=$table{'color1'}><td colspan=4><font$font_para size=2>\n";
print "Name: <input type=text name=name size=20 maxlength=40> ";
print "E-mail:<input type=text name=email size=20> <i>(both required)</i><br>";
print "Check here if you want to hide your email address: <input type=\"checkbox\" name=\"hide\">";
print "</font></td></tr>\n";

Thanks.

Petskull
Maniac (V) Mad Scientist

From: 127 Halcyon Road, Marenia, Atlantis
Insane since: Aug 2000

posted posted 01-06-2003 04:58

wouldn't this:

$words = array( "evil word", //obviously replace this with the words you want to detect"foul word",);

fuck up the whole thing by commenting out ,);?



Code - CGI - links - DHTML - Javascript - Perl - programming - Magic - http://www.twistedport.com
ICQ: 67751342

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 01-06-2003 18:49

well, it shouldn't, petskull. after all, it only comments out the rest of the line, and there's a linebreak afterwards.

I assume the problem lays more in the fact that it's a php script, which you're trying to paste into a perl script.
Sorry, I can't help you with perl, I don't know enough about it, but petskull is the local perl guru around here...

The Jackal
Paranoid (IV) Inmate

From: The Dark Side of the Moon
Insane since: Jun 2000

posted posted 01-06-2003 20:07

Well, Pet, any thoughts?

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 01-06-2003 20:39

I'm looking at this script and totally lost on where you want to do this.

But try replacing this:
<BLOCKQUOTE><FONT face="Verdana, Arial">code:</font><HR><pre>
foreach $line (@lines) {
my ($dbname, $name, $desc, $level) = split(/\

Piper
Paranoid (IV) Inmate

From: California
Insane since: Jun 2000

posted posted 01-06-2003 21:31

I haven't had a chance to look at the code yet but it should just be a simple substitution. Something like this will work:

code:
my $text = 'This is a test of bad word substitution.  Let\'s see if the bloody thing works!';
my %bad = (
bad => 'good',
bloody => 'damn',
);

$text =~ s/(\w+)/ exists $bad{$1} ? $bad{$1} : $1 /oesg;



Just store your bad words in a hash. I'll take a look at the code when I get home and see if I can put it in context for you.

Regards,
Charlie

[edit]doh, bitdamaged beat me to it.[/edit]


[This message has been edited by Piper (edited 01-06-2003).]

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 01-06-2003 21:35

dammit I knew it could be done in one line. I'm always learning with perl



.:[ Never resist a perfect moment ]:.

Piper
Paranoid (IV) Inmate

From: California
Insane since: Jun 2000

posted posted 01-06-2003 21:44
quote:
I'm always learning with perl



Isn't that the truth!

That bit of code is something I found when I was making a generic template parser. It has turned out to be quite versatile.

~Charlie

Piper
Paranoid (IV) Inmate

From: California
Insane since: Jun 2000

posted posted 01-07-2003 05:13

I'm lost looking at that code too. The only place I can see to filter bad names is around the line 130 area of showquiz.pl:

Original Code
<BLOCKQUOTE><FONT face="Verdana, Arial">code:</font><HR><pre>
if (param('name') eq ""

The Jackal
Paranoid (IV) Inmate

From: The Dark Side of the Moon
Insane since: Jun 2000

posted posted 01-08-2003 21:23

Thanks for the help Piper. I added the code as you suggested and I did get an error. The error log told me this:


syntax error at ./showquiz.pl line 131, near "

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 01-09-2003 00:25

yep first UBB (this forum) put's a space between two "pipes" (

Piper
Paranoid (IV) Inmate

From: California
Insane since: Jun 2000

posted posted 01-09-2003 02:22

Thanks, bitdamaged. I did not notice that when I lookd over the code.

The Jackal: I did test that regex and it works. It's a bit overkill for single word names but it will catch multi word names which I think you probably want. I just hope the code is in the right spot to filter the name.

~Charlie

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 01-09-2003 04:06

Yeah that's one of those things you'll miss, it just comes up in this forum everytime someone uses an or operator



.:[ Never resist a perfect moment ]:.

Petskull
Maniac (V) Mad Scientist

From: 127 Halcyon Road, Marenia, Atlantis
Insane since: Aug 2000

posted posted 01-09-2003 05:05

damn.. looks like I'm late!

What's the question again?


Code - CGI - links - DHTML - Javascript - Perl - programming - Magic - http://www.twistedport.com
ICQ: 67751342

The Jackal
Paranoid (IV) Inmate

From: The Dark Side of the Moon
Insane since: Jun 2000

posted posted 01-12-2003 09:16

Mega Kudos to Piper and Bit! The new addition works wonderfully! I will name my first born after you!

Piper
Paranoid (IV) Inmate

From: California
Insane since: Jun 2000

posted posted 01-12-2003 17:19

Awesome, I'm glad that worked for you.

~Charlie

« BackwardsOnwards »

Show Forum Drop Down Menu