calderawp / location
Get GeoIP data via IP
dev-master
2016-08-13 23:32 UTC
Requires
This package is auto-updated.
Last update: 2024-11-08 07:43:40 UTC
README
Turns an IP address into GeoIP data.
Requires PHP7
Install
composer require calderawp/location
Usage
Find IP via http://freegeoip.net/ :
$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
:
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;
}
}