Welcome to WebmasterWorld Guest from 54.205.119.93

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)

5+ Year Member



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 Sep 12, 2008 (gmt 0)

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



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 Sep 12, 2008 (gmt 0)

5+ Year Member



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 Sep 12, 2008 (gmt 0)

5+ Year Member



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 Sep 12, 2008 (gmt 0)

5+ Year Member



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 Sep 14, 2008 (gmt 0)

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



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 Sep 19, 2008 (gmt 0)

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



welcome to WebmasterWorld [webmasterworld.com], bormg!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month