Welcome to WebmasterWorld Guest from 23.22.220.37

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

script help

programming dummy looking for help

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

New User

5+ Year Member

joined:Sept 1, 2008
posts: 4
votes: 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";

3:03 pm on Sept 12, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 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.

7:16 pm on Sept 12, 2008 (gmt 0)

Preferred Member

10+ Year Member

joined:Jan 5, 2006
posts:536
votes: 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]

8:35 pm on Sept 12, 2008 (gmt 0)

New User

5+ Year Member

joined:Sept 1, 2008
posts:4
votes: 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.

9:26 pm on Sept 12, 2008 (gmt 0)

Preferred Member

10+ Year Member

joined:Jan 5, 2006
posts:536
votes: 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.

3:15 pm on Sept 14, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 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";

7:55 pm on Sept 19, 2008 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10542
votes: 8


welcome to WebmasterWorld [webmasterworld.com], bormg!