Forum Moderators: coopster & phranque

Message Too Old, No Replies

simple ip redirect script

         

nobody9999 9

4:43 pm on Oct 25, 2004 (gmt 0)



I use a simple script to redirect user base on their IP

use Socket;
$ipaddr = $ENV{'REMOTE_ADDR'};
;
if ($ipaddr[0] == '123.456.789.000')
{
print "Location: [yahoo.com\n\n";...]
}
else
{
print "Location: [google.com\n\n";...]
}

the problem is that, only the first two parts of the ip address are compared
user with IP 123.456.#*$!.xxx will direct to yahoo.
the last two "dot" parts(*.*.789.000) of the ip address weren't compared........
just wondering how to fix it if i just want the ip of 123.456.789.000 to visit a specific page?

thank you

upside

11:27 pm on Oct 25, 2004 (gmt 0)

10+ Year Member



Are you trying to match the first 3 octets or the whole IP?

if you want to match the whole IP then use:

if ($ipaddr[0] eq '123.456.789.000')

otherwise try:

if ($ipaddr[0] =~ m/^123\.456\.789\./)