如何在PHP项目中创建GeoIP功能? [英] How create GeoIP functionality in PHP project?
问题描述
我有一些IP地址( $ _ SERVER ['REMOTE_ADDR']
),我必须收到(学习)国家名称,如果我可以收到学习)城市的名字。不要忘记它是php-project,非常有用的API。
PS 这是一些开源项目,我们只能使用免费和开源工具。
无(只需要'GeoIP.dat'文件)。要下载免费的GeoIP标准国家
数据库,请转到
http:// maxmind .com / download / geoip / database /
安装
只需放置'geoip。 inc'文件根据
'php.ini'文件的'include_path'指令,或者将它放在与PHP脚本相同的目录中。
用法
通过主机名获取国名:
include geoip.inc);
$ gi = geoip_open(/ usr / local / share / GeoIP / GeoIP.dat,GEOIP_STANDARD);
echo geoip_country_code_by_addr($ gi,24.24.24.24)。 \t。
geoip_country_name_by_addr($ gi,24.24.24.24)。 \\\
;
echo geoip_country_code_by_addr($ gi,80.24.24.24)。 \t。
geoip_country_name_by_addr($ gi,80.24.24.24)。 \\\
;
HTH。
I have some IP adress ($_SERVER['REMOTE_ADDR']
) and I must receive (learn) name of country and it would be nice if I can receive (learn) name of city too. And don't forget It's php-project, useful API - very good.
P.S. It's some open-source project and we must use only free and open-source tools.
None (only the 'GeoIP.dat' file is needed). To download a free GeoIP Standard Country database, go to http://maxmind.com/download/geoip/database/
Install
Just place the 'geoip.inc' file somewhere according to the 'include_path' directive of your 'php.ini' file, or just place it in the same directory as your PHP scripts.
Usage
Gets country name by hostname :
include("geoip.inc");
$gi = geoip_open("/usr/local/share/GeoIP/GeoIP.dat",GEOIP_STANDARD);
echo geoip_country_code_by_addr($gi, "24.24.24.24") . "\t" .
geoip_country_name_by_addr($gi, "24.24.24.24") . "\n";
echo geoip_country_code_by_addr($gi, "80.24.24.24") . "\t" .
geoip_country_name_by_addr($gi, "80.24.24.24") . "\n";
HTH.
这篇关于如何在PHP项目中创建GeoIP功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!