i can cobble scripts together and whatnot, but my knowledge of cgi/perl is very limited. i have a simple guestbook script i have been using for years, and it suites me well... i have modified it some to allow people to check a box and add themselves to my mailing list, and i incorporated google recaptcha (thanks to users from daniweb helping me) as well...
what i am looking for now, is some code to insert to allow the script not to publish if it contains certain words...

i have been blasted with spam, (even with the recaptcha installed)... and almost every post is containing the word UGG (ugg boots)

i want the script to not post if anywhere, there is the word UGG (or others, as i see fit)
and have it show the word that is not allowed in the error page..
ie.. sorry, you used the word UGG, go back and retry

how can i do this?
thank you
pj

you can use a regex to check the incomming posting comments againts a list of words. This is a quick and dirty example.

#!/usr/bin/perl

use strict;
use warnings;

my @Blocked_Words = <DATA>;
my $Incomming_Comments = "the Fat rat ate the bat and come and join the Hippie's";

my $check = grep { $Incomming_Comments =~ /$_/ig } @Blocked_Words;

#this will also report the total found.

die("The post contains blocked words.\n") if $check >= 1;



__DATA__
Rat
bat
fat
work
hippie
computer

Hi wickedxter,

Though your script compile, but will produce no output, because there is no match in your regex. Since each of the value read into the array variable @Blocked_Words has a trailing "\n".

check this using use re qw(debug); in your script.

However, doing chomp(my @Blocked_Words = <DATA>); resolves this issue.

Secondly, why not just exit as soon as a "blocked" word is seen? Instead of reading all blocked words into an array variable. like so:

use strict;
use warnings;

my $Incomming_Comments =
  qq{the Fat rat ate the bat and come and join the Hippie's};
while (<DATA>) {
    chomp;
    die("The post contains blocked words.\n") if $Incomming_Comments =~ /$_/ig;
}

__DATA__
Rat
bat
fat
work
hippie
computer

Hi pjrey,

I think it would be good if we can have a glimpse of the part of your code, you really want to work on. If not maybe wickedxter's example would give you a headup.

thanks for responding... here is a bit of the code:

 &valid_page;
  $the_date=localtime();
  &findbook;
  &decode_vars;
  &test_required;
  &check_captcha;
  &valid_address;
  &setup_pageentry;
  &setup_thankyounote;
  &send_thanks;
 if (($TELL_ME eq "YES" && $MY_EMAIL ne "") || 
       ($TELL_ME eq "NO" && $MY_EMAIL ne ""))  
   { &notify_me;}
  if ($fields{'private'} ne "YES")
   { &write_entry;}
  if ( -e $tempmail )
   { unlink($tempmail);}

  print "Location: $GUESTBOOK_URL\n\n";
  exit;

sub send_thanks




  $SBJ = "thanks";
  $fltime = time;
  $flip = $ENV{'REMOTE_ADDR'};
  $flip =~s/\.//g;
  if ($flip eq "")
    { $flip = "123456";}
  $tmpxname=($fltime ^ $flip);
  $tempmail="$TEMPDIR/$tmpxname.bbb";
  open (OTM,">$tempmail");
  print OTM "\n";
  print OTM "$THANK_YOU\n\n";
  close (OTM);
  open(IMZ,"<$tempmail"); 
  @mailtext=<IMZ>;             
  close(IMZ);              

if ($BAD_EMAIL_FORMAT eq "NO" && $SEND_THANKS eq "YES")
 {
# IF YOU ARE USING WINDOWS 95/98/NT with BLAT.EXE UNCOMMENT THE LINE BELOW
# system ("$MAIL_PROGRAM $tempmail -t $fields{'signer_email'} -f $MY_EMAIL -s \"$SBJ\" -q");

  open (MZ,"|$MAIL_PROGRAM") || die "Content-type: text/html\n\n Unable to send mail";


  print MZ "To: $fields{'signer_email'}\n";
  print MZ "From: $MY_EMAIL\n";
  print MZ "Subject: $SBJ\n";

  foreach $tomail (@mailtext)
   {
     print MZ "$tomail";
   }
# END OF UNIX PROGRAM CODE
  close (MZ);
 }
}

##################################################################
# NOTE! Windows 95/98/NT users will have to edit this routine
##################################################################
sub notify_me
{

  if ($BAD_EMAIL_FORMAT eq "YES")
   { 
     $SBJ = "Guestbook was signed- left no email for you"; 
     $tmpename=$MY_EMAIL;
   }
   else
   { 
    $SBJ = "the book has been signed";
    $tmpename=$fields{'signer_email'};
   }

# IF YOU ARE USING WINDOWS 95/98/NT with BLAT.EXE UNCOMMENT THE LINE BELOW
# system ("$MAIL_PROGRAM $tempmail -t $MY_EMAIL -f $tmpename -s \"$SBJ\" -q");

  open (MZT,"|$MAIL_PROGRAM") || die "Content-type: text/html\n\n Unable to send mail"; 

# IF YOU ARE USING BLAT.EXE, COMMENT THE LINES THAT FOLLOW
# BY PLACING A # SIGN AT THE START OF THE LINE. DO THIS UNTIL
# YOU GET TO THE LINE THAT READS: END OF UNIX PROGRAM CODE

  print MZT "To: $MY_EMAIL\n";
  print MZT "From: $tmpename\n";
  print MZT "Subject: $SBJ\n";

  foreach $tomail (@mailtext)
   {
     print MZT "$tomail";
   }
# END OF UNIX PROGRAM CODE
  close (MZT);

}

##################################################################
sub test_required
{
 foreach $tst (@mandatory)
  {
   if ($fields{$tst} eq "")
    {
     $errmesg ="<B>hey you, you didn't fill in all of the required information.<BR>";
     $errmesg .= "press your BACK BUTTON to return to the entry form!</B>";
     &error_exit;
    }
 }
}

where did ya gooo?

hellooo

Hi pjrey,

What do you want to discuss? We are all here

hmm, thought i stated it in initial post.. what i am looking for now, is some code to insert to allow the script not to publish if it contains certain words... (i have a censer funtion currently there, *** out bad words***... but i want the script not to process the form if it contains certian words.
thanks
pj

... but i want the script not to process the form if it contains certian words.

I thought that has also be shown in the past on this same post expect you hae something else in mind. Please check my post over a month ago...

Thanks

yes, i remember i did try out your code, kept getting 500 errors so i gave up and quit...
i since fixed a majority of spam by creating a required checkbox that only humans will UNcheck... and that seemed to clear a bit up...
thanks
pj

Hi pj,
If this thread is then solved. Please can you mark it solved.

Thank you

its not though, your code didnt work inside... someone asked to see a snippet... so shared.
where would i insert yoru code? i tried a couple differnt things, nothing seemed to work.

I don't get what you are trying to accomplish? 2teez has already answered how to deal with validating the incoming input (string). Where do you need to add the snippet portion? It should be right after you accept an input and before you save/post it in your dabase (if you do save). The check would be either allow it to be saved/posted or reject it. It could be as early as before find_book subroutine if you want to. Or it could be inside your test_required subroutine.

PS: Don't simply copy & paste. You need to adapt it to your own use & variables.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.