homepage Welcome to WebmasterWorld Guest from 54.197.215.146
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
script help
programming dummy looking for help
bormg




msg:3743542
 2:19 pm on Sep 12, 2008 (gmt 0)

My existing script replaces bad words with ****. I would like to modify it so when it finds the bad words, it just terminates the script or gives an error for them to resubmit.

the code below is where the script does the replacement. Can this be done and if so could someone point me in the direction. As a perl dummy I have tried several thing without success. I thought I could use some sort of counter and if the count was > 1 just send an error.
Any help would be appreciated
Thanks in advance

my $word;
foreach $word(@badwords){ $FORM{$_} =~ s/$word/$censored/gisex; }
$line .="$FORM{$_}$separator";
$field{$_}=1;
if ($FORM{$_} (!$only_fields_with_values)) {
$message.="$_: " unless $send_just_data;
$message.="$FORM{$_}\n";

 

rocknbil




msg:3743573
 3:03 pm on Sep 12, 2008 (gmt 0)

Welcome aboard bormg! With perl, as always, there's more than one way to do it. Here's one:

my ($word,$score,$wordlimit);
$score = 0;
$wordlimit=5; # for example

foreach $word(@badwords){
if ($FORM{$_} =~ /$word/ig) { $score++; }
}

if ($score > $wordlimit) { &return_to_form; }

... Where "&return_to_form" is a call to the sub that generates the form, fields populated. &return_to_form should output the form and immediately exit so there's no need for an "else" following the if:


sub return_to_form {
my ($form);
$form = qq¦
<html><head><title>Error</title></head>
<body>
<form method="post" action="yourscript.cgi">
<input type="text" name="fname" value="$FORM{'fname'}">
(and so on)
</form>
</body>
</html>
¦;
print "content-type: text/html\n\n";
print $form;
exit 0;
}

Set $wordlimit to 0 to have it stop if any of the words are found.

perl_diver




msg:3743803
 7:16 pm on Sep 12, 2008 (gmt 0)

as a side note, all word censors/filters are fairly easy to circumvent. Anyone that uses forums knows that.

[edited by: phranque at 7:51 pm (utc) on Sep. 19, 2008]
[edit reason] filter cirumvention [/edit]

bormg




msg:3743853
 8:35 pm on Sep 12, 2008 (gmt 0)

It never ceases to amaze me of the knowledge you guys have and willingness to help someone out on here.

Thanks!
Worked like a charm.

perl_diver




msg:3743878
 9:26 pm on Sep 12, 2008 (gmt 0)

Bills code might be better written like this:



foreach $word(@badwords){
if ($FORM{$_} =~ /$word/ig) {
if ($score++ > $wordlimit) {
&return_to_form;
last;
}
}

it gets out of the loop as soon as possible instead of waiting until all words are checked.

rocknbil




msg:3744622
 3:15 pm on Sep 14, 2008 (gmt 0)

TMTOWTDI defined! :-P

as a side note, all word censors/filters are fairly easy to circumvent.

But you can slow them down. :-)

$in = 'this is my in with the word [test it]';

@bad_words = ('add','words','here');

foreach $word (@bad_words) {
@letters = split ('',$word);
$regexp = join ('.*',@letters);
$in =~ s/$regexp/\*\*\*\*\*\*/ig;
}

print "$in";

phranque




msg:3748214
 7:55 pm on Sep 19, 2008 (gmt 0)

welcome to WebmasterWorld [webmasterworld.com], bormg!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved