2017 © Pedro Peláez
 

library lumen-geoip

GeoIP for Lumen

image

salmaabdelhady/lumen-geoip

GeoIP for Lumen

  • Thursday, April 12, 2018
  • by SalmaAbdelhady
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 7 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

GeoIP for Lumen

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Determine the geographical location of website visitors based on their IP addresses., (*2)

Installation

To install this package, just install through composer, (*3)

$ composer require salmaabdelhady/lumen-geoip

Providers

Next, open bootstrap/app.php and add under the Register Service Providers section:, (*4)

...
$app->register(Codenexus\GeoIP\GeoIPServiceProvider::class);

Update MaxMind GeoLite2 City database

Run this on the command line from the root of your project:, (*5)

$ php artisan geoip:update

Usage

GeoIP will try to determine the IP using the following http headers: HTTP_CLIENT_IP, HTTP_X_FORWARDED_FOR, HTTP_X_FORWARDED, HTTP_X_CLUSTER_CLIENT_IP, HTTP_FORWARDED_FOR, HTTP_FORWARDED, REMOTE_ADDR in this order. Optionally you can set an IP as the only parameter to set it., (*6)

$record = app()->geoip->getLocation('232.223.11.11');
$record = GeoIP::getLocation('232.223.11.11'); // If you have enabled facades

print($record->country->isoCode . "\n"); // 'US'
print($record->country->name . "\n"); // 'United States'
print($record->country->names['zh-CN'] . "\n"); // '美国'

print($record->mostSpecificSubdivision->name . "\n"); // 'Minnesota'
print($record->mostSpecificSubdivision->isoCode . "\n"); // 'MN'

print($record->city->name . "\n"); // 'Minneapolis'

print($record->postal->code . "\n"); // '55455'

print($record->location->latitude . "\n"); // 44.9733
print($record->location->longitude . "\n"); // -93.2323

Other Methods

These methods are also available to use within your applications., (*7)

app()->geoip->checkIp($ip) // Checks IP to make sure IP is a valid IPv4 or IPv6 address and not within a private or reserved range
app()->geoip->getIp() // Returns the detected client IP

Default Location Data

When an IP is not detected it will be set to 127.0.0.1 which will ultimately throw an Exception. If you are not in production your record will default to the following data., (*8)

array (
    "ip"           => "232.223.11.11",
    "isoCode"      => "US",
    "country"      => "United States",
    "city"         => "New Haven",
    "state"        => "CT",
    "postal_code"  => "06510",
    "lat"          => 41.28,
    "lon"          => -72.88,
    "timezone"     => "America/New_York",
    "continent"    => "NA",
    "default"      => false
);

Change Log

v2.0.0

  • Simplified namespace
  • Added Facade support
  • Added default location when in development
  • Fixed bug where detected IP was always blank

The Versions

12/04 2018

dev-master

9999999-dev

GeoIP for Lumen

  Sources   Download

MIT

The Requires

 

by Jeremy Schaffer
by CodeNexus, LLC

geoip php lumen codenexus

12/04 2018

2.0.3

2.0.3.0

GeoIP for Lumen

  Sources   Download

MIT

The Requires

 

by Jeremy Schaffer
by CodeNexus, LLC

geoip php lumen codenexus

13/11 2016

v2.0.2

2.0.2.0

GeoIP for Lumen

  Sources   Download

MIT

The Requires

 

by Jeremy Schaffer
by CodeNexus, LLC

geoip php lumen codenexus

12/11 2016

v2.0.1

2.0.1.0

GeoIP for Lumen

  Sources   Download

MIT

The Requires

 

by Jeremy Schaffer
by CodeNexus, LLC

geoip php lumen codenexus

23/08 2016

v2.0.0

2.0.0.0

GeoIP for Lumen

  Sources   Download

MIT

The Requires

 

by Jeremy Schaffer
by CodeNexus, LLC

geoip php lumen codenexus

23/08 2016

dev-develop

dev-develop

GeoIP for Lumen

  Sources   Download

MIT

The Requires

 

by Jeremy Schaffer
by CodeNexus, LLC

geoip php lumen codenexus

21/08 2016

v2.0.0-RC

2.0.0.0-RC

GeoIP for Lumen

  Sources   Download

MIT

The Requires

 

by Jeremy Schaffer
by CodeNexus, LLC

geoip php lumen codenexus

13/10 2015

v1.0.0

1.0.0.0

GeoIP for Lumen

  Sources   Download

MIT

The Requires

 

by Jeremy Schaffer
by CodeNexus, LLC

geoip php lumen codenexus