You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$dispatcher = newDispatcher([
newMiddlewares\ClientIp(),
function ($request) {
//Get the client ip$ip = $request->getAttribute('client-ip');
}
]);
$response = $dispatcher->dispatch(newServerRequest());
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.
//Use proxies$middleware = (newMiddlewares\ClientIp())->proxy();
//Trust only some proxies by ip$middleware = (newMiddlewares\ClientIp())->proxy(['10.10.10.10', '10.10.10.11']);
//Trust only some proxies by ip using a specific header$middleware = (newMiddlewares\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 = (newMiddlewares\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:
//Save the ip in the "ip" attribute$middleware = (newMiddlewares\ClientIp())->attribute('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.
About
PSR-15 middleware to detect the client ip and save it as a request attribute.