Install PHP GeoIP
# apt-get install geoip-bin geoip-database geoip-database-extra php5-geoip php5-geos
Updating GeoIP database from SID (choose your mirror)
# wget http://kambing.ui.ac.id/debian/pool/main/g/geoip-database/geoip-database-extra_20160912-1_all.deb
# wget http://kambing.ui.ac.id/debian/pool/main/g/geoip-database/geoip-database_20160912-1_all.deb
# dpkg -i geoip-database_20160912-1_all.deb
# dpkg -i geoip-database-extra_20160912-1_all.deb
To convert IP to integer
$ip = ip2long('119.249.54.66');
To convert integer to IP
$hostip = long2ip($ip);
To get 3 chars country code
echo geoip_country_code3_by_name($hostip);
To get country name
echo geoip_country_name_by_name($hostip);
To get country code and region
echo var_dump(geoip_region_by_name($hostip))."<br>";
Error: mod_fcgid: stderr: PHP Warning: geoip_region_by_name(): Required database not available at /usr/share/GeoIP/GeoIPRegion.dat. ??? May be required subscription premium service ???
No comments:
Post a Comment