jeff5656 Posted August 19, 2009 Share Posted August 19, 2009 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" Quote Link to comment https://forums.phpfreaks.com/topic/171026-picking-out-part-an-ip-address/ Share on other sites More sharing options...
Bricktop Posted August 19, 2009 Share Posted August 19, 2009 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"; } Quote Link to comment https://forums.phpfreaks.com/topic/171026-picking-out-part-an-ip-address/#findComment-901998 Share on other sites More sharing options...
lostprophetpunk Posted August 19, 2009 Share Posted August 19, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/171026-picking-out-part-an-ip-address/#findComment-902004 Share on other sites More sharing options...
ignace Posted August 19, 2009 Share Posted August 19, 2009 $octets = explode('.', $_SERVER['REMOTE_ADDR']); if (20 == $octets[1]) { //downtown office } Quote Link to comment https://forums.phpfreaks.com/topic/171026-picking-out-part-an-ip-address/#findComment-902005 Share on other sites More sharing options...
ignace Posted August 19, 2009 Share Posted August 19, 2009 $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) Quote Link to comment https://forums.phpfreaks.com/topic/171026-picking-out-part-an-ip-address/#findComment-902006 Share on other sites More sharing options...
jeff5656 Posted August 19, 2009 Author Share Posted August 19, 2009 got 3 new replies.. will try these out.. Quote Link to comment https://forums.phpfreaks.com/topic/171026-picking-out-part-an-ip-address/#findComment-902008 Share on other sites More sharing options...
jeff5656 Posted August 19, 2009 Author Share Posted August 19, 2009 Ok I tried the list one. It works. Very elegant. Thanks for all the replies Quote Link to comment https://forums.phpfreaks.com/topic/171026-picking-out-part-an-ip-address/#findComment-902011 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.