ip2locaton

Discussion in 'PHP' started by tolgafiratoglu, Oct 14, 2007.

  1. #1
    Hi,
    I remember I used a service once I can't remember it's URL now,

    I was sending an IP as a query, and that site was sending country, city, etc. as a response to me back as a string.

    Do you remember it?

    Thanks.
     
    tolgafiratoglu, Oct 14, 2007 IP
  2. Dakuipje

    Dakuipje Peon

    Messages:
    931
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <?php
        function ip2c($lookup_ip) {
            $ip = $lookup_ip;
            $country = file_get_contents("http://api.hostip.info/get_html.php?ip=".$ip."&position=true",false);
            preg_match("/country: (.*?)\ncity: (.*?)\nlatitude: (.*?)\nlongitude: (.*?)$/i",$country,$result);
            return $result;
        }
    
        $data =  ip2c("24.26.73.230");
        echo "Country: ".$data[1]."<br />";
        echo "City / State: ".$data[2]."<br />";
        echo "Latitude: ".$data[3]."<br />";
        echo "Longitude: ".$data[4]."<br />";
    ?>
    PHP:
     
    Dakuipje, Oct 14, 2007 IP
  3. daboss

    daboss Guest

    Messages:
    2,249
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #3
    well, what do you know... :) just click on the tools menu in dp itself! :D
     
    daboss, Oct 14, 2007 IP
  4. tolgafiratoglu

    tolgafiratoglu Well-Known Member

    Messages:
    249
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #4
    thanks for your help :)
     
    tolgafiratoglu, Oct 14, 2007 IP