Skip to content

Files

Latest commit

c59b061 · May 20, 2012

History

History
92 lines (63 loc) · 3.26 KB

README.md

File metadata and controls

92 lines (63 loc) · 3.26 KB

Fuel Ipinfodb Geolocation Package

A super simple IP Geolocation package using the Ipinfodb API for use with FuelPHP.

With this package and API you can obtain the country code, region name (state), city, zipcode, latitude, longitude, and timezone all in an easy to use associative array.

About

Installation

Git Submodule

If you are installing this as a submodule (recommended) in your git repo root, run this command:

$ git submodule add git://github.com/dustinbolton/fuel-ipinfodb.git fuel/packages/ipinfodb

Then you you need to initialize and update the submodule:

$ git submodule update --init --recursive fuel/packages/ipinfodb/

###Download

Alternatively you can download it and extract it into fuel/packages/ipinfodb/.

Configuration

Configuration is easy. First thing you will need to do is to register for your Ipinfodb API key (if you haven't already; it's free!).

Next, copy the packages/ipinfodb/config/ipinfodb.php from the package up into fuel's app/config/ directory. Open it up and enter your API key. You may optionally change the default geolocation precision level from city to country if you only need country-level precision.

Usage

The package must either be loaded by defining in your app's config.php -> always_load -> packages section as "ipinfodb" or manually loaded via Package::load( 'ipinfodb' );. An optional second parameter may have the value city or country to change the geolocation precision level.

$ip_address = Input::ip(); // IP address of visitor.
$response = Ipinfodb::locate( $ip_address ); // Geolocate.
echo '<pre>' . print_r( $response, true ) . '</pre>'; // Print out response array contents.

For more information about the API see Ipinfodb API Documentation.

Example Response

Ipinfodb::locate( '207.97.227.239' ); returns:

Array
(
    [statusCode] => OK
    [statusMessage] => 
    [ipAddress] => 207.97.227.239
    [countryCode] => US
    [countryName] => UNITED STATES
    [regionName] => TEXAS
    [cityName] => SAN ANTONIO
    [zipCode] => 78218
    [latitude] => 29.5614
    [longitude] => -98.4126
    [timeZone] => -06:00
)

For more information about the API responses see Ipinfodb API Documentation.

Updates

In order to keep the package up to date simply run:

$ git submodule update --recursive fuel/packages/ipinfodb/

License

Copyright 2012 Dustin Bolton

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.