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

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);

Replies are listed 'Best First'.
Re: Testing form params
by b10m (Vicar) on Jan 13, 2004 at 12:26 UTC

    *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