geoip_db_filename
(PECL geoip >= 1.0.1)
geoip_db_filename — 返回 GeoIP 数据库相对应的文件名
说明
geoip_db_filename(int
$database
): stringgeoip_db_filename() 函数将会返回和 GeoIP 数据库相对应的文件名。
这个函数不会判别文件是否存在在磁盘上,只会表明拓展库在哪里查找数据库。
返回值
成功则返回相对应的数据库文件名,错误则返回null
。
范例
示例 #1 geoip_db_filename()函数的使用范例:
如下代码将会打印数据库相对应的文件名。
<?php
print geoip_db_filename(GEOIP_COUNTRY_EDITION);
?>
以上例程会输出:
/usr/share/GeoIP/GeoIP.dat

User Contributed Notes 1 note
Loc d'Anterroches ¶
11 years ago
To quickly know which databases are available on your system:
<?php
$cst = array(
'GEOIP_COUNTRY_EDITION' => GEOIP_COUNTRY_EDITION,
'GEOIP_REGION_EDITION_REV0' => GEOIP_REGION_EDITION_REV0,
'GEOIP_CITY_EDITION_REV0' => GEOIP_CITY_EDITION_REV0,
'GEOIP_ORG_EDITION' => GEOIP_ORG_EDITION,
'GEOIP_ISP_EDITION' => GEOIP_ISP_EDITION,
'GEOIP_CITY_EDITION_REV1' => GEOIP_CITY_EDITION_REV1,
'GEOIP_REGION_EDITION_REV1' => GEOIP_REGION_EDITION_REV1,
'GEOIP_PROXY_EDITION' => GEOIP_PROXY_EDITION,
'GEOIP_ASNUM_EDITION' => GEOIP_ASNUM_EDITION,
'GEOIP_NETSPEED_EDITION' => GEOIP_NETSPEED_EDITION,
'GEOIP_DOMAIN_EDITION' => GEOIP_DOMAIN_EDITION,
);
foreach ($cst as $k=>$v) {
echo $k.': '.geoip_db_filename($v).' '.(geoip_db_avail($v) ? 'Available':'').'<br>';
}
?>
The only drawback of the PECL extension with respect to a pure PHP implementation is that you cannot select yourself where the database is. So, if you get a new version of the database, you need to put in the standard place and you may need root access to do so.
备份地址:http://www.lvesu.com/blog/php/function.geoip-db-filename.php