I want to get visitors country via their IP... Right now I'm using this (http://api.hostip.info/country.php?ip=...... )
Here is my code:
<?php
if (isset($_SERVER['HTTP_CLIENT_IP']))
{
$real_ip_adress = $_SERVER['HTTP_CLIENT_IP'];
}
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$real_ip_adress = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$real_ip_adress = $_SERVER['REMOTE_ADDR'];
}
$cip = $real_ip_adress;
$iptolocation = 'http://api.hostip.info/country.php?ip=' . $cip;
$creatorlocation = file_get_contents($iptolocation);
?>
Well, it's working properly, but the thing is, this returns the country code like US or CA., and not the whole country name like United States or Canada.
So, is there any good alternative to hostip.info offers this?
I know that I can just write some code that will eventually turn this two letters to whole country name, but I'm just too lazy to write a code that contains all countries...
P.S: For some reason I don't want to use any ready made CSV file or any code that will grab this information for me, something like ip2country ready made code and CSV.
A one liner with an IP address to country API
Example :
https://ipapi.co/country_name/ - your country
https://ipapi.co/8.8.8.8/country_name/ - country for IP 8.8.8.8
Try this simple PHP function.
How to use:
Example1: Get visitor IP address details
Example 2: Get details of any IP address. [Support IPV4 & IPV6]
There is a well-maintained flat-file version of the ip->country database maintained by the Perl community at CPAN
Access to those files does not require a dataserver, and the data itself is roughly 515k
Higemaru has written a PHP wrapper to talk to that data: php-ip-country-fast
Use following services
1) http://api.hostip.info/get_html.php?ip=12.215.42.19
2)
3) http://ipinfodb.com/ip_location_api.php
My service ipdata.co provides the country name in 5 languages! As well as the organisation, currency, timezone, calling code, flag, Mobile Carrier data, Proxy data and Tor Exit Node status data from any IPv4 or IPv6 address.
It's also extremely scalable with 10 regions around the world each able to handle >10,000 requests per second!
The options include; English (en), German (de), Japanese (ja), French (fr) and Simplified Chinese (za-CH)
you can use http://ipinfo.io/ to get details of ip address Its easy to use .