Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get country code and currency code by IP-address? [closed]

I am new in zend Framework. And i want to get currency code, country code by the ip-address.

Can i have any example url?.

Please Help me...

Thanks in advance.

like image 674
Manoj Avatar asked Apr 21 '11 08:04

Manoj


People also ask

Can you tell country from IP address?

From there, you can try using other online tools to find the owner of the IP address. However, note that you can't find someone's exact location by IP address. You can use an IP to map out the city, state, or country an IP address comes from, but you won't be able to track someone down from their IP alone.

How can I get current country name in PHP?

The geoip_country_name_by_name() function will return the full country name corresponding to a hostname or an IP address.


2 Answers

Get detailed country code, currency, currency converter, currency symbol etc from http://www.geoplugin.net/json.gp?ip="ip address here"

enter image description here

like image 124
Md. Zubaer Ahammed Avatar answered Sep 28 '22 02:09

Md. Zubaer Ahammed


You can use my service, the http://ipinfo.io API to get the country code:

function get_country($ip) {
    return file_get_contents("http://ipinfo.io/{$ip}/country");
}

echo get_country("8.8.8.8"); // => US

If you're interested in other details you could make a more generic function:

function ip_details($ip) {
    $json = file_get_contents("http://ipinfo.io/{$ip}");
    $details = json_decode($json);
    return $details;
}

$details = ip_details("8.8.8.8");

echo $details->city;     // => Mountain View
echo $details->country;  // => US
echo $details->org;      // => AS15169 Google Inc.
echo $details->hostname; // => google-public-dns-a.google.com

I've used the IP 8.8.8.8 in these examples, but if you want details for the user's IP just pass in $_SERVER['REMOTE_ADDR'] instead. More details are available at http://ipinfo.io/developers

You can get a mapping of country codes to currency codes from http://country.io/data/ and add that to your code. Here's a simple example:

function getCurrenyCode($country_code) {
    $currency_codes = array(
        'GB' => 'GBP',
        'FR' => 'EUR',
        'DE' => 'EUR',
        'IT' => 'EUR',
    );

    if(isset($currency_codes[$country_code])) {
        return $curreny_codes[$country_code];
    }

    return 'USD'; // Default to USD
}
like image 31
Ben Dowling Avatar answered Sep 28 '22 04:09

Ben Dowling