【发布时间】:2013-05-22 21:49:33
【问题描述】:
http://chir.ag/projects/geoiploc/
您好,我正在尝试进行设置,但是每当我使用 include("geoiploc.php"); 时,页面都是空白的,每当我删除 include("geoiploc.php"); 时,我只会看到我的 IP 地址。我已将 geoiploc.php 和 index.php 上传到可以运行 PHP 的虚拟主机。
如果还有其他更简单的方法可以通过 IP 或任何其他方式显示国家/地区名称,是哪一种?请问我需要这个快
所以正如我所说,每当我删除 include("geoiploc.php"); 时它只会显示我的 IP,为什么?
你需要这个库:http://chir.ag/projects/geoiploc/autogen/geoiploc.tar.gz 这是运行脚本的代码:
include("geoiploc.php"); // Must include this
// ip must be of the form "192.168.1.100"
// you may load this from a database
$ip = $_SERVER["REMOTE_ADDR"];
echo "Your IP Address is: " . $ip . "<br />";
echo "Your Country is: ";
// returns country code by default
echo getCountryFromIP($ip);
echo "<br />\n";
// optionally, you can specify the return type
// type can be "code" (default), "abbr", "name"
echo "Your Country Code is: ";
echo getCountryFromIP($ip, "code");
echo "<br />\n";
// print country abbreviation - case insensitive
echo "Your Country Abbreviation is: ";
echo getCountryFromIP($ip, "AbBr");
echo "<br />\n";
// full name of country - spaces are trimmed
echo "Your Country Name is: ";
echo getCountryFromIP($ip, " NamE ");
echo "<br />\n";
【问题讨论】: