Skip to content

Instantly share code, notes, and snippets.

@vordan
Last active June 27, 2021 09:16
Show Gist options
  • Save vordan/26d4ee244db26e9f8cac2d3360fb710d to your computer and use it in GitHub Desktop.
Save vordan/26d4ee244db26e9f8cac2d3360fb710d to your computer and use it in GitHub Desktop.
Installing PHP GeoIP on UbuntuTo make GeoIP work on PHP
# 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.
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
<?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.
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment