Spread the love

The GeoIP extension allows you to find the location of an IP address. Like the city, state, country, latitude, and longitude.

sudo wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz sudo gunzip GeoLiteCity.dat.gz sudo mkdir -v /usr/share/GeoIP sudo mv -v GeoLiteCity.dat /usr/share/GeoIP/GeoIPCity.dat sudo apt-get install php-geoip
Code language: JavaScript (javascript)

And here is an example how to use it with PHP7:

$ip = $_SERVER['REMOTE_ADDR']; $country = geoip_country_name_by_name($ip); echo 'The current user is located in: ' . $country;
Code language: PHP (php)

Facebook Comments Box