2017 © Pedro Peláez
 

library geolocation

Middleware to geolocate the client using the ip address

image

middlewares/geolocation

Middleware to geolocate the client using the ip address

  • Saturday, January 27, 2018
  • by oscarotero
  • Repository
  • 2 Watchers
  • 4 Stars
  • 125 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 7 Versions
  • 160 % Grown

The README.md

middlewares/geolocation

Latest Version on Packagist ![Software License][ico-license] Testing ![Total Downloads][ico-downloads] ![SensioLabs Insight][ico-sensiolabs], (*1)

Middleware to geolocate the client using the ip address and Geocoder and save the result as a request attribute., (*2)

Requirements

Installation

This package is installable and autoloadable via Composer as middlewares/geolocation., (*3)

composer require middlewares/geolocation

Example

$freeGeoIpProvider = new Geocoder\Provider\FreeGeoIp($adapter);

$dispatcher = new Dispatcher([
    new Middlewares\Geolocation($freeGeoIpProvider),

    function ($request) {
        //Get the client location
        $location = $request->getAttribute('client-location');

        $country = $location->first()->getCountry();
    }
]);

$response = $dispatcher->dispatch(new ServerRequest());

Options

__construct(Geocoder\Provider\Provider $provider)

The geocoder provider used to geolocate the client., (*4)

It's also recommended to configure it to caching responses., (*5)

ipAttribute(string $ipAttribute)

By default uses the REMOTE_ADDR server parameter to get the client ip. This option allows to use a request attribute. Useful to combine with a ip detection middleware, for example client-ip., (*6)

attribute(string $attribute)

The attribute name used to store the client addresses in the server request. By default is client-location., (*7)


Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details., (*8)

The MIT License (MIT). Please see LICENSE for more information., (*9)

The Versions

21/09 2017

v0.4.0

0.4.0.0 https://github.com/middlewares/geolocation

Middleware to geolocate the client using the ip address

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 geolocation server http ip psr-15 geocode

26/12 2016

v0.3.0

0.3.0.0 https://github.com/middlewares/geolocation

Middleware to geolocate the client using the ip address

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 geolocation server http ip psr-15 geocode

27/11 2016

v0.2.0

0.2.0.0 https://github.com/middlewares/geolocation

Middleware to geolocate the client using the ip address

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 geolocation server http ip psr-15 geocode

10/10 2016

v0.1.0

0.1.0.0 https://github.com/middlewares/geolocation

Middleware to geolocate the client using the ip address

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 geolocation server http ip psr-15 geocode