1.
CD geoip/
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
gzip-d GeoIP.dat.gz
ls
GeoLiteCity.dat
Other libraries: viewing
http://dev.maxmind.com/zh-hans/geoip/legacy/geolite/
2.
wget http://www.maxmind.com/download/geoip/api/php/php-latest.tar.gz
Unzip php-latest.tar.gz
3. Use
Include ("/www/web/develop/marketsystem/common/lib/geoip-api-php-1.14/src/geoip.inc");
Get the country. The IP
function Getcountrybyip ($ip) {
$gi = Geoip_open ("/www/web/develop/marketsystem/common/lib/geoip/ GeoIP.dat ", Geoip_standard);
if (Strstr ($ip, ":")) {
$country _code = geoip_country_code_by_addr_v6 ($gi, $ip);
$country _name = geoip_country_name_by_addr_v6 ($gi, $ip);
else{
$country _code = geoip_country_code_by_addr ($gi, $ip);
$country _name = geoip_country_name_by_addr ($gi, $IP);
Geoip_close ($GI);
return [
"Country_code" => $country _code,
"country_name" => $country _name,
];
}