2017 © Pedro Peláez
 

library geoip

Geoip Wrapper with Laravel 4 & 5 Support

image

pulkitjalan/geoip

Geoip Wrapper with Laravel 4 & 5 Support

  • Friday, December 1, 2017
  • by pulkitjalan
  • Repository
  • 7 Watchers
  • 54 Stars
  • 99,534 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 23 Forks
  • 0 Open issues
  • 25 Versions
  • 5 % Grown

The README.md

IP Geolocation

IP Geolocation Wrapper with Laravel Support, (*1)

Latest Stable Version Total Downloads License, (*2)

This package provides an easy way to get geolocation information from IP addresses. It supports multiple drivers including IP-API, MaxMind Database, MaxMind API, IPStack, IP2Location, and IPinfo., (*3)

Requirements

  • PHP >= 8.1

Installation

Install via composer:, (*4)

composer require pulkitjalan/ip-geolocation

Laravel

There is a Laravel service provider and facade available., (*5)

Add the following to the providers array in your config/app.php, (*6)

PulkitJalan\IPGeolocation\IPGeolocationServiceProvider::class

Next add the following to the aliases array in your config/app.php, (*7)

'IPGeolocation' => PulkitJalan\IPGeolocation\Facades\IPGeolocation::class

Next publish the config file:, (*8)

php artisan vendor:publish --provider="PulkitJalan\IPGeolocation\IPGeolocationServiceProvider" --tag="config"

Using an older version of PHP / Laravel?

If you are on a PHP version below 8.1 or a Laravel version below 9.0, use an older version of this package., (*9)

Usage

The ipGeolocation class takes a config array as the first parameter or defaults to using the ip-api driver., (*10)

Example:, (*11)

<?php

use PulkitJalan\IPGeolocation\IPGeolocation

$ip = new IPGeolocation();

$lat = $ip->getLatitude(); // 51.5141
$lon = $ip->getLongitude(); // -3.1969

IP-API

To use the ip-api pro service you can set the options in your config., (*12)

Pro Example:, (*13)

$config = [
    'driver' => 'ip-api',
    'ip-api' => [
        'key' => 'YOUR IP-API KEY',
    ],
];

Maxmind Database

To use Maxmind database as the driver you can set the options in your config., (*14)

Database Example:, (*15)

$config = [
    'driver' => 'maxmind_database',
    'maxmind_database' => [
        'database' => '/path/to/database.mmdb',
    ],
];

Maxmind Api

To use Maxmind api as the driver you can set the options in your config., (*16)

Web API Example:, (*17)

$config = [
    'driver' => 'maxmind_api',
    'maxmind_api' => [
        'user_id' => 'YOUR MAXMIND USER ID',
        'license_key' => 'YOUR MAXMIND LICENSE KEY'
    ],
];

IPStack

To use the ipstack as the driver set the config., (*18)

Example:, (*19)

$config = [
    'driver' => 'ipstack',
    'ipstack' => [
        'key' => 'YOUR IPSTACK KEY',
        'secure' => true, // (optional) use https
    ],
];

IP2Location

To use IP2Location as the driver, set the config as follows:, (*20)

Example:, (*21)

$config = [
    'driver' => 'ip2location',
    'ip2location' => [
        'api_key' => 'YOUR IP2LOCATION API KEY',
    ],
];

IPinfo

To use IPinfo as the driver, set the config as follows:, (*22)

Example:, (*23)

$config = [
    'driver' => 'ipinfo',
    'ipinfo' => [
        'token' => 'YOUR IPINFO API TOKEN',
    ],
];

Laravel

To use this package in Laravel, simply update the config file in config/ip-geolocation.php to get the same effect. The driver can be set using the IPGEOLOCATION_DRIVER env., (*24)

Available Methods

IPGeolocation will try to determin the ip using the following http headers: HTTP_CLIENT_IP, HTTP_X_FORWARDED_FOR, HTTP_X_FORWARDED, HTTP_FORWARDED_FOR, HTTP_FORWARDED, REMOTE_ADDR in this order. Optionally use the setIp method to set it., (*25)

$ip->setIp('127.0.0.1');

// Laravel
IPGeolocation::setIp('127.0.0.1');

There are a number of available methods to pull out the required information. All methods will return an empty string if data is unavailable., (*26)

Get latitude, (*27)

$ip->getLatitude();

// Laravel
IPGeolocation::getLatitude();

Get longitude, (*28)

$ip->getLongitude();

// Laravel
IPGeolocation::getLongitude();

Get city, (*29)

$ip->getCity();

// Laravel
IPGeolocation::getCity();

Get country, (*30)

$ip->getCountry();

// Laravel
IPGeolocation::getCountry();

Get country code, (*31)

$ip->getCountryCode();

// Laravel
IPGeolocation::getCountryCode();

Get region, (*32)

$ip->getRegion();

// Laravel
IPGeolocation::getRegion();

Get region code, (*33)

$ip->getRegionCode();

// Laravel
IPGeolocation::getRegionCode();

Get postal code, (*34)

$ip->getPostalCode();

// Laravel
IPGeolocation::getPostalCode();

Get timezone, (*35)

$ip->getTimezone();

// Laravel
IPGeolocation::getTimezone();

Get isp (not supported on all drivers), (*36)

$ip->getIsp();

// Laravel
IPGeolocation::getIsp();

Get all geo information, (*37)

$ip->get(); // returns array

// Laravel
IPGeolocation::get(); // returns array

Get raw geo information, (*38)

$ip->getRaw(); // different drivers will return different data types

// Laravel
IPGeolocation::getRaw(); // different drivers will return different data types

Update Database

There is an update command available to help with updating and installing a local ip geolocation database. The following will download and install/update the database file to /path/to/database.mmdb. As of 30th December 2019, Maxmind requires users to create an account and use a license key to download the databases., (*39)

<?php

use PulkitJalan\IPGeolocation\IPGeolocationUpdater

$config = [
    'driver' => 'maxmind_database',
    'maxmind_database' => [
        'database' => '/path/to/database.mmdb',
        'license_key' => 'YOUR MAXMIND LICENSE KEY'
    ],
];

(new IPGeolocationUpdater($config))->update();

Laravel

Once you have registered the service provider (supports auto discovery), you can use the command php artisan ip-geolocation:update, (*40)

Services

IP-API

IP-API is a free (or paid) service that can be used instead of the database file or the paid MaxMind service. They do have some limitations on the free service, so please review their documentation first., (*41)

MaxMind

You can use the free database from MaxMind (license key required) or their web API service. You can sign up and get a free license key here., (*42)

IPStack

IPStack is a real-time IP to geolocation API service. They offer both free and paid plans. You can find more information and sign up on their website., (*43)

IP2Location

IP2Location provides IP geolocation databases and web services. They offer various products and services, including both free and paid options. You can learn more and sign up on their website., (*44)

IPinfo

IPinfo is a comprehensive IP address data provider offering accurate geolocation, ASN, company, and other IP-related information. They provide both API and database download options. You can sign up for a free API key or explore their paid plans on their website., (*45)

License

The MIT License (MIT). Please see the License File for more information., (*46)

The Versions

01/12 2017

dev-master

9999999-dev https://github.com/pulkitjalan/geoip

Geoip Wrapper with Laravel 4 & 5 Support

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip maxmind ip-api telize freegeoip

01/12 2017

2.6.1

2.6.1.0 https://github.com/pulkitjalan/geoip

Geoip Wrapper with Laravel 4 & 5 Support

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip maxmind ip-api telize freegeoip

01/12 2017

2.6.0

2.6.0.0 https://github.com/pulkitjalan/geoip

Geoip Wrapper with Laravel 4 & 5 Support

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip maxmind ip-api telize freegeoip

26/01 2017

2.5.0

2.5.0.0 https://github.com/pulkitjalan/geoip

Geoip Wrapper with Laravel 4 & 5 Support

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip maxmind ip-api telize freegeoip

10/08 2016

2.4.0

2.4.0.0 https://github.com/pulkitjalan/geoip

Geoip Wrapper with Laravel 4 & 5 Support

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip maxmind ip-api telize freegeoip

10/08 2016

2.3.1

2.3.1.0 https://github.com/pulkitjalan/geoip

Geoip Wrapper with Laravel 4 & 5 Support

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip maxmind ip-api telize

10/08 2016

2.3.0

2.3.0.0 https://github.com/pulkitjalan/geoip

Geoip Wrapper with Laravel 4 & 5 Support

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip maxmind ip-api telize

15/06 2016

2.2.2

2.2.2.0 https://github.com/pulkitjalan/geoip

Geoip Wrapper with Laravel 4 & 5 Support

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip maxmind ip-api telize

20/02 2016

2.2.1

2.2.1.0 https://github.com/pulkitjalan/geoip

Geoip Wrapper with Laravel 4 & 5 Support

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip maxmind ip-api telize

29/11 2015

2.2.0

2.2.0.0 https://github.com/pulkitjalan/geoip

Geoip Wrapper with Laravel 4 & 5 Support

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip maxmind ip-api telize

07/10 2015

2.1.0

2.1.0.0 https://github.com/pulkitjalan/geoip

Geoip Wrapper with Laravel 4 & 5 Support

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip maxmind ip-api telize

17/07 2015

2.0.2

2.0.2.0 https://github.com/pulkitjalan/geoip

Geoip Wrapper with Laravel 4 & 5 Support

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip maxmind ip-api telize

17/07 2015

1.0.x-dev

1.0.9999999.9999999-dev https://github.com/pulkitjalan/geoip

Geoip Wrapper with Laravel 4 & 5 Support

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip maxmind ip-api telize

17/07 2015

1.0.9

1.0.9.0 https://github.com/pulkitjalan/geoip

Geoip Wrapper with Laravel 4 & 5 Support

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip maxmind ip-api telize

16/07 2015

2.0.1

2.0.1.0 https://github.com/pulkitjalan/geoip

Geoip Wrapper with Laravel 4 & 5 Support

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip maxmind ip-api telize

16/07 2015

1.0.8

1.0.8.0 https://github.com/pulkitjalan/geoip

Geoip Wrapper with Laravel 4 & 5 Support

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip maxmind ip-api telize

16/07 2015

2.0.0

2.0.0.0 https://github.com/pulkitjalan/geoip

Geoip Wrapper with Laravel 4 & 5 Support

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip maxmind ip-api telize

16/07 2015

1.0.7

1.0.7.0 https://github.com/pulkitjalan/geoip

Geoip Wrapper with Laravel 4 & 5 Support

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip maxmind ip-api telize

27/02 2015

1.0.6

1.0.6.0 https://github.com/pulkitjalan/geoip

Geoip Wrapper with Laravel 4 & 5 Support

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip maxmind ip-api telize

25/01 2015
13/01 2015
12/01 2015
12/01 2015
11/01 2015
11/01 2015

1.0.0

1.0.0.0 https://github.com/pulkitjalan/geoip

Geoip Wrapper with Laravel Support

  Sources   Download

MIT

The Requires

 

The Development Requires

geoip maxmind ip-api