ip address if statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

ip address if statement

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

almost

Post 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&#1111;'REMOTE_ADDR'], strlen($m)) == 0) 
&#123; 
print('192.111.0.50');
&#125; 
else 
&#123; 
print('12.211.111.211:1601');
&#125;
?>

The problem is that it is always returning the ELSE... any clue?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
Post Reply