GeoIP is a way to get location from an IP.

In PHP there are many ways to get that but the best way to get that is to keep the MaxMind database and use that.

first, we need

composer require geoip2/geoip2

Then:

Download “geoip.mmdb” database from MaxMind

Then:

use GeoIp2\Database\Reader;

require_once './vendor/autoload.php';

$reader = new Reader('./geoip.mmdb');

 $record = $reader->city('192.168.0.1');
 
 print_r($record);

Download MaxMind City database from Github

To use this easily with other providers you can use “torann/geoip

Ahmad Eyamin