calderawp/location

Get GeoIP data via IP

dev-master 2016-08-13 23:32 UTC

This package is auto-updated.

Last update: 2024-12-08 07:54:48 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;
    		}
    	}

Copyright 2016 CalderaWP LLC & Josh Pollock. Licensed under the terms of the GNU GPL version 2 or later. Please share with your neighbor.