问题:
I want to get visitors country via their IP... Right now I'm using this ( http://api.hostip.info/country.php?ip= ...... )我想通过他们的 IP 获取访问者的国家...现在我正在使用这个( 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?那么,hostip.info 有什么好的替代方案吗?
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...我知道我可以编写一些代码,最终将这两个字母转换为整个国家/地区的名称,但我懒得编写包含所有国家/地区的代码......
PS: 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. PS:出于某种原因,我不想使用任何现成的 CSV 文件或任何可以为我获取此信息的代码,例如 ip2country 的现成代码和 CSV。
解决方案:
参考一: https://stackoom.com/question/qfeK参考二: Getting visitors country from their IP