Page 1 of 1
ip address if statement
Posted: Fri May 02, 2003 2:46 pm
by romeo
I need a hand...
<clap><clap>
I need to write a link into a page depending on the IP address of the visitor
i.e. if the visito comes from 192.40.40.* the link is this, else the link is this1
sounds simple but couldnt find the PHP function let alone how to accomplish the host mask.
Posted: Fri May 02, 2003 2:54 pm
by volka
Code: Select all
$m = '192.40.40.';
if (strncmp($m, $_SERVER['REMOTE_ADDR'], strlen($m)) == 0)
{
}
else
{
}
http://www.php.net/manual/de/function.strncmp.php
almost
Posted: Fri May 02, 2003 3:22 pm
by romeo
Alrighty, so the deal is "if your on my local network go here, else go here... here is what i have.. thnak you
Code: Select all
<?
$m = "192.111.0.;
if (strncmp($m, $_SERVERї'REMOTE_ADDR'], strlen($m)) == 0)
{
print('192.111.0.50');
}
else
{
print('12.211.111.211:1601');
}
?>
The problem is that it is always returning the ELSE... any clue?
Posted: Fri May 02, 2003 5:43 pm
by volka
work quite right for me
Code: Select all
<?php
$m = '192.168.0.';
echo $_SERVER['REMOTE_ADDR'], '<br />';
echo $m, '<br />';
if (strncmp($m, $_SERVER['REMOTE_ADDR'], strlen($m)) == 0)
{
print('local network');
}
else
{
print('world');
}
?>
done.
my webserver is reachable via 192.168.0.1 or world interface