此功能可通过IP获取国家省市信息,需要自行下载IP库放入程序目录中。
注意:只支持PHP8.1及以上版本!
下载地址:github上搜Geo-lite2之类的关键词有很多数据库,找最新的下载
将GeoLite2-City.mmdb
文件,放入/core/plugin/Geoip2/ipdb/
目录中即可。
下载地址:github上搜Geo-lite2之类的关键词有很多数据库,找最新的下载
将GeoLite2-Country.mmdb
文件,放入/core/plugin/Geoip2/ipdb/
目录中即可。
下载CZDB格式数据库,将文件重命名为cz88.czdb
放到/core/plugin/Geoip2/ipdb/
目录。
创建一个cz88.crt
空文件,把纯真密钥保存进去,放到/core/plugin/Geoip2/ipdb/
目录。
//加载模块 LOAD::plugin("Geoip2/geoip2"); $Geoip2 = new Geoip2(); //获取IP信息 $Geoip2->query("49.67.241.93", $dbtype = "geoip2"); //$dbtype 使用的IP数据库,支持 geoip2、geoip2-country、cz88 //geoip2 返回国家,省,市数据,数据库比较大 Array ( [ip] => 49.67.241.93 [intranet] => [type] => ipv4 [continent] => 亚洲 [continent_code] => AS [country] => 中国 [country_code] => CN [province] => 江苏省 [province_code] => JS [city] => 南通 [address] => 中国南通 ) //geoip2-country 只返回国家信息,数据库比较小,速度快 Array ( [ip] => 49.67.241.93 [intranet] => [type] => ipv4 [continent] => 亚洲 [continent_code] => AS [country] => 中国 [country_code] => CN [address] => 中国 ) //cz88 返回省市数据 Array ( [ip] => 49.67.241.93 [intranet] => [type] => ipv4 [country] => 中国 [province] => 江苏 [city] => 南通 [districts] => [address] => 中国南通 [isp] => 电信 [original] => 中国–江苏–南通 电信 )