2017 © Pedro Peláez
 

library client-ip

Middleware to detect the client ip and save it as a request attribute

image

middlewares/client-ip

Middleware to detect the client ip and save it as a request attribute

  • Thursday, June 28, 2018
  • by oscarotero
  • Repository
  • 3 Watchers
  • 6 Stars
  • 14,631 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 12 Versions
  • 12 % Grown

The README.md

middlewares/client-ip

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

Middleware to detect the client ip and save it as a request attribute., (*2)

Requirements

Installation

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

composer require middlewares/client-ip

Usage

$dispatcher = new Dispatcher([
    new Middlewares\ClientIp(),

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

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

proxy

This option configures the detection through proxies. The first argument is an array of ips or cidr of the trusted proxies. If it's empty, no ip filtering is made. The second argument is a list of the headers to inspect. If it's not defined, uses the default value ['Forwarded', 'Forwarded-For', 'Client-Ip', 'X-Forwarded', 'X-Forwarded-For', 'X-Cluster-Client-Ip']. Disabled by default., (*4)

//Use proxies
$middleware = (new Middlewares\ClientIp())->proxy();

//Trust only some proxies by ip
$middleware = (new Middlewares\ClientIp())->proxy(['10.10.10.10', '10.10.10.11']);

//Trust only some proxies by ip using a specific header
$middleware = (new Middlewares\ClientIp())->proxy(['10.10.10.10', '10.10.10.11'], ['X-Forwarded-For']);

// Trust only some proxies by cidr range
// usefull when you have an autoscaled proxy(like haproxy) in a subnet
$middleware = (new Middlewares\ClientIp())->proxy(['192.168.0.0/16', '10.0.0.0/8']);

attribute

By default, the ip is stored in the client-ip attribute of the server request. This options allows to modify that:, (*5)

//Save the ip in the "ip" attribute
$middleware = (new Middlewares\ClientIp())->attribute('ip');

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

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

The Versions

28/06 2018

dev-master

9999999-dev https://github.com/middlewares/client-ip

Middleware to detect the client ip and save it as a request attribute

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 server http ip psr-15

28/06 2018
28/04 2018
27/01 2018

v1.0.0

1.0.0.0 https://github.com/middlewares/client-ip

Middleware to detect the client ip and save it as a request attribute

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 server http ip psr-15

13/11 2017
21/09 2017

v0.6.0

0.6.0.0 https://github.com/middlewares/client-ip

Middleware to detect the client ip and save it as a request attribute

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 server http ip psr-15

19/09 2017

dev-fix/upgrade-middleware

dev-fix/upgrade-middleware https://github.com/middlewares/client-ip

Middleware to detect the client ip and save it as a request attribute

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 server http ip psr-15

13/07 2017

v0.5.0

0.5.0.0 https://github.com/middlewares/client-ip

Middleware to detect the client ip and save it as a request attribute

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 server http ip psr-15

13/04 2017

v0.4.0

0.4.0.0 https://github.com/middlewares/client-ip

Middleware to detect the client ip and save it as a request attribute

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 server http ip psr-15

26/12 2016

v0.3.0

0.3.0.0 https://github.com/middlewares/client-ip

Middleware to detect the client ip and save it as a request attribute

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 server http ip psr-15

27/11 2016

v0.2.0

0.2.0.0 https://github.com/middlewares/client-ip

Middleware to detect the client ip and save it as a request attribute

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 server http ip psr-15

10/10 2016

v0.1.0

0.1.0.0 https://github.com/middlewares/client-ip

Middleware to detect the client ip and save it as a request attribute

  Sources   Download

MIT

The Requires

 

The Development Requires

middleware psr-7 server http ip psr-15