- PHP

How to get Geolocation in PHP

The easiest way to do that is to:

  • Provide the specific IP or get the client IP with $_SERVER[‘REMOTE_ADDR’].
  • Check the interesting data with APIs such as Geoplugin or FreeGeoIP.

Example:

<?php
  $ip = '127.0.0.1';
  echo var_export(unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $ip)));
?>