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";
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.