14/08
2016
Wallogit.com
2017 © Pedro Peláez
Get GeoIP data via IP
Turns an IP address into GeoIP data., (*1)
Requires PHP7, (*2)
composer require calderawp/location, (*3)
Find IP via http://freegeoip.net/ :, (*4)
$geo = new FreeGEOIP( '1.2.3.5' );
$geo->query();
$location = $geo->get_location();
Free GEOIP is rate limitted, you can deploy your own instance. But then you will need to write your own handler class. Here is an example, assuming your API is at http://HiRoy.club/geo :, (*5)
class MyGeoIP extends GEOIP
{
/**
* @inheritdoc
*/
protected function apiRoot() : string
{
return 'http://HiRoy.club/geo/json/';
}
/**
* @inheritdoc
*/
protected function getApiUrl( string $ip ) : string
{
return $this->apiRoot() . $ip;
}
}