Jump to content

picking out part an ip address


jeff5656

Recommended Posts

Hi jeff5656,

 

Would this work?  In this example I'm just looking for .20. in the IP address.

 

if(strstr($ip,.20.)) 
{
echo "downtown office.";
} 

 

Or using explode you could match the second string exactly:

 

list($octet1, $octet2,$octet3,$octet4) = explode(".", $ip, 4);
if($octet2 == "20")
{
echo "Downtown Office";
}

Lets say if do this:

 

$ip = $_server['REMOTE_ADDR'];

 

And lets say I get

10.20.30.40

 

How do I identify the second of of numbers (i.e. 20).

 

I want to say "if the second set is 20, then $site = "downtown office"

 

 

 

$ip = $_server['REMOTE_ADDR'];

$list($first,$second,$third,$fourth) = explode('.',$ip);
// $second is the second part of the IP Adress
// just use the variables as needed, as in echoing them out... echo $first, $second; (you get the point)

 

Hope this helped.

$ip = $_server['REMOTE_ADDR'];

$list($first,$second,$third,$fourth) = explode('.',$ip);
// $second is the second part of the IP Adress
// just use the variables as needed, as in echoing them out... echo $first, $second; (you get the point)

 

should be:

 

$ip = $_server['REMOTE_ADDR'];

list($first,$second,$third,$fourth) = explode('.',$ip);
// $second is the second part of the IP Adress
// just use the variables as needed, as in echoing them out... echo $first, $second; (you get the point)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.