#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    6
    Rep Power
    0
    I am making a PHP script that extracts information from the access_log file in apache. So thats no problem but when i get the ipaddress from the file i split it by using explode function and i get 4 seperate numbers and the third number i am using as a subnet. This tells me what region is accessing the page on my co. intranet. So say New York equals 165 through 167, Boston equals 161-164. How in the php script will i do that the easiest. I got it working using a bunch of if and elseif statments but that seems like such a dumb way to do it. Can anyone help me?????? here is an example of my code:
    if ($ip2 == 165){
    $region = New York;
    }elseif ($ip2 == 166){
    $region = New York;
    }elseif ($ip2 == 161){
    $region = Boston;
    }
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    5
    Rep Power
    0
    ?(($ip2-165)<0) : ($region=Boston) : ($region=New York);
    If you can sure there will be only these two regions, use this.

    Or this:
    If ($ip2>=161 AND $ip2<=164) {
    $region = Boston;
    } elseif ($ip2>=165 AND $ip2<=167){
    $region = New York;
    }

    I suggests u write this prog separately, the judgement (judge the range of $ip2) and the definition(with the judgement, set $region), that will make ur prog easy to read, if the region is more than two, consider to using the switch statment.

    [This message has been edited by eggli (edited June 29, 2000).]

    [This message has been edited by eggli (edited June 29, 2000).]
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    6
    Rep Power
    0
    Thanks a lot it worked. I am new to programming so I am always doing things the hard way.

    I had to use the second way because there were 13 regions. Is that the easiest way to do this.

    Thanks

Similar Threads

  1. PHP3 Introduction
    By guest in forum Development Articles
    Replies: 571
    Last Post: June 11th, 2003, 07:39 AM

IMN logo majestic logo threadwatch logo seochat tools logo