2017 © Pedro Peláez
 

library stack-geo-ip

Geolocation Stack middleware for Geocoder library.

image

geocoder-php/stack-geo-ip

Geolocation Stack middleware for Geocoder library.

  • Tuesday, October 28, 2014
  • by couac
  • Repository
  • 6 Watchers
  • 39 Stars
  • 413 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 8 Forks
  • 1 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

StackGeoIp

Geolocation Stack middleware that adds geolocation results to the request for subsequent middlewares by leveraging the Geocoder library., (*1)

Build
Status, (*2)

Usage

Example

Here we create a simple application that returns the IP address of the request and the contents of the X-Country header to the browser. Normally, the X-Country header would not exists., (*3)

By wrapping the GeoIP middleware around it using the StackBuilder, if the IP address can be matched to a country, the X-Country header will be set to the two-letter code for that country, and be available to the application., (*4)

<?php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;

require __DIR__ . '/vendor/autoload.php';

$app = new \Silex\Application();

$app->get('/', function(Request $request) {
    $ip      = $request->getClientIp();
    $country = $request->headers->get('X-Country', 'UNKNOWN');

    return new Response($ip . ' => '. $country, 200);
});

$stack = (new \Stack\Builder())
    ->push('Geocoder\Stack\GeoIp')
    ;

$app = $stack->resolve($app);

$request  = Request::createFromGlobals();
$response = $app->handle($request)->send();
$app->terminate($request, $response);

Options

The following options can be used:, (*5)

  • adapter (optional): The Geocoder HTTP adapter to use. Defaults to cURL adapter., (*6)

  • provider (optional): The Geocoder provider to use. Defaults to the FreeGeoIP provider. For production, it is recommended to use a provider that relies on local files rather than HTTP requests, such as Max Mind binary provider., (*7)

  • header (optional): The name of the HTTP header to store the country result in. Defaults to "X-Country"., (*8)

See the Geocoder documentation for a list of available adapters and providers., (*9)

Intallation

The recommended way to install StackGeoIp is through Composer:, (*10)

json { "require": { "geocoder-php/stack-geo-ip": "@stable" } }, (*11)

Protip: you should browse the geocoder-php/stack-geo-ip page to choose a stable version to use, avoid the @stable meta constraint., (*12)

License

StackGeoIp is released under the MIT License. See the bundled LICENSE file for details., (*13)

The Versions

28/10 2014

dev-master

9999999-dev

Geolocation Stack middleware for Geocoder library.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andy Leon

stack geolocation geocoder

28/10 2014

1.0.3

1.0.3.0

Geolocation Stack middleware for Geocoder library.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andy Leon

stack geolocation geocoder

28/10 2014

1.0.2

1.0.2.0

Geolocation Stack middleware for Geocoder library.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andy Leon

stack geolocation geocoder

18/04 2014

1.0.1

1.0.1.0

Geolocation Stack middleware for Geocoder library.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andy Leon

stack geolocation geocoder

17/09 2013

1.0.0

1.0.0.0

Geolocation Stack middleware for Geocoder library.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andy Leon

stack geolocation geocoder

11/09 2013

0.0.1

0.0.1.0

Geolocation Stack middleware for Geocoder library.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andy Leon

stack geolocation geocoder