-1

I want to get all country names from IP addresses. I have a CSV file in which all IP addresses are described and I want to get all country names at once. Any have an idea how to do it?

I am using the code below, but it works only for single values. How can I do this for multiple IP addresses?

<form method="post">
  <input type="text" name="ip" />
  <input type="submit" name="submit" value="Find" />
</form>

<?php

function countryCityFromIP($ipAddr) {
    $url="http://api.ipinfodb.com/v3/ip-city/?key=5cfaab6c5af420b7b0f88d289571b990763e37b66761b2f053246f9db07ca913&ip=$ipAddr&format=json%22";
    $d = file_get_contents($url);
    return json_decode($d , true);
}

if(isset($_REQUEST['submit'])){
    $ip=countryCityFromIP($_REQUEST['ip']);
    print_r($ip);
    echo $ip['countryName'];
}

?>
Racil Hilan
  • 24,690
  • 13
  • 50
  • 55
ritika
  • 1
  • 4

1 Answers1

0

Here is updated code

The input should be comma-separated list of IP addresses

<form method="post">
  <input type="text" name="ip" />
  <input type="submit" name="submit" value="Find" />
</form>

<?php

function countryCityFromIP($ipAddr) {
    $url="http://api.ipinfodb.com/v3/ip-city/?key=5cfaab6c5af420b7b0f88d289571b990763e37b66761b2f053246f9db07ca913&ip=$ipAddr&format=json%22";
    $d = file_get_contents($url);
    return json_decode($d , true);
}

if(isset($_REQUEST['submit'])){
    foreach(explode(',', $_REQUEST['ip']) as $ip) {
        $ip = countryCityFromIP($ip[);
        print_r($ip);
        echo $ip['countryName'];
    }

}

?>
ruX
  • 7,224
  • 3
  • 39
  • 33
  • looking this code $url = json_decode(file_get_contents("http://api.ipinfodb.com/v3/ip-city/?key=2b3d7d0ad1a285279139487ce77f3f58d980eea9546b5ccc5d08f5ee62ce7471&ip=".'124.40.244.19'."&format=json")); echo $url->countryName; – ritika Sep 21 '16 at 04:59
  • in this code i want to enter multiple ip addresses so please tell me how can i do it. – ritika Sep 21 '16 at 05:01