vordan
5/6/2017 - 12:39 PM

Installing PHP GeoIP on Ubuntu To make GeoIP work on PHP ( all the functions in http://php.net/manual/en/book.geoip.php ), php5-geoip and G

Installing PHP GeoIP on Ubuntu

To make GeoIP work on PHP ( all the functions in http://php.net/manual/en/book.geoip.php ), php5-geoip and GeoCityLite.dat must be installed.

<?php 

$ip_address = $_SERVER['REMOTE_ADDR'];
echo"$ip_address, ";
$ip_country = geoip_country_code_by_name ($ip_address);
echo"$ip_country";

// See PHP manual for more functions http://php.net/manual/en/ref.geoip.php like city or ISP.

?>
apt-get install php5-geoip
mkdir /usr/local/share/GeoIP
cd /usr/share/local/GeoIP
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
gunzip GeoLiteCity.dat.gz
service apache2 restart