middlewares/client-ip

Name: client-ip

Owner: Middlewares

Description: PSR-15 middleware to detect the client ip and save it as a request attribute.

Created: 2016-10-10 07:30:19.0

Updated: 2018-04-28 10:44:30.0

Pushed: 2018-04-28 10:45:36.0

Homepage: null

Size: 37

Language: PHP

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

middlewares/client-ip

Latest Version on Packagist Software License Build Status Quality Score Total Downloads SensioLabs Insight

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

Requirements
Installation

This package is installable and autoloadable via Composer as middlewares/client-ip.

oser require middlewares/client-ip
Example
patcher = new Dispatcher([
new Middlewares\ClientIp(),

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


ponse = $dispatcher->dispatch(new ServerRequest());
Options
proxy(array $ips = [], array $headers = [])

Configure the detection through proxies. The first argument is an array of ips 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.

e proxies
dleware = (new Middlewares\ClientIp())->proxy();

ust only some proxies by ip
dleware = (new Middlewares\ClientIp())->proxy(['10.10.10.10', '10.10.10.11']);

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

Used to get the ip from localhost environment using http://ipecho.net/plain. Disabled by default.

attribute(string $attribute)

The attribute name used to store the ip in the server request. By default is client-ip.


Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details.

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


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.