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.
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.
The geoip_country_name_by_name() function will return the full country name corresponding to a hostname or an IP address.
Get detailed country code, currency, currency converter, currency symbol etc from http://www.geoplugin.net/json.gp?ip="ip address here"
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With