in reply to Re: Re: Testing form params
in thread Testing form params

No need for grep here :)

open(BANNED, "<$banned"); while(<BANNED>) { print "GET AWAY!" if ($_ eq $ENV{REMOTE_ADDR}); } close BANNED;
--
b10m

Replies are listed 'Best First'.
Re: Re: Testing form params
by Anonymous Monk on Jan 13, 2004 at 12:04 UTC
    I tried your code..well, I changed a little bit to get it to work, but it won't die and tell me my IP is bad. Did I mess something up? (I checked the banned.txt file and it has my IP with no leading spaces and I saved the IP via print BANNED "$ENV{'REMOTE_ADDR'}\n";
    open(BANNED, "<$banned") or die "Cannot open $banned because: $!"; while(<BANNED>) { if ($_ eq $ENV{REMOTE_ADDR}) { print "<font color=red>Your IP has been banned, you are not allow +ed to use this script.</font>\n"; exit; } } close(BANNED);

      *Doh!*, my bad, $ENV{REMOTE_ADDR} doesn't have a line break, so you might want to chomp the input first:

      open(BANNED, "<$banned") || die "Can't open $banned: $!"; while(<BANNED>) { chomp; if($_ eq $ENV{REMOTE_ADDR}) { print "... you are banned ..."; exit; } } close BANNED;

      update: If you use Apache, you also might want to use it's blocking capabilities :)

      --
      b10m