Functionality for determining client IP address.

package Default

 Methods

Returns client IP address.

getIpAddress() : string

Returns

stringIP address.

Checks proxy handling setting.

getUseProxy() : boolean

Returns

booleanCurrent setting value.

Set the header to introspect for proxy IPs

setProxyHeader(string $header = 'X-Forwarded-For') : \Zend\Http\PhpEnvironment\RemoteAddress

Parameters

$header

string

Returns

\Zend\Http\PhpEnvironment\RemoteAddress

Set list of trusted proxy addresses

setTrustedProxies(array $trustedProxies) : \Zend\Http\PhpEnvironment\RemoteAddress

Parameters

$trustedProxies

array

Returns

\Zend\Http\PhpEnvironment\RemoteAddress

Changes proxy handling setting.

setUseProxy(boolean $useProxy = true) : \Zend\Http\PhpEnvironment\RemoteAddress

This must be static method, since validators are recovered automatically at session read, so this is the only way to switch setting.

Parameters

$useProxy

boolean

Whether to check also proxied IP addresses.

Returns

\Zend\Http\PhpEnvironment\RemoteAddress

Attempt to get the IP address for a proxied client

getIpAddressFromProxy() : false | string
see

Returns

falsestring

Normalize a header string

normalizeProxyHeader(string $header) : string

Normalizes a header string to a format that is compatible with $_SERVER

Parameters

$header

string

Returns

string

 Properties

 

HTTP header to introspect for proxies

$proxyHeader : string

Default

'HTTP_X_FORWARDED_FOR'
 

List of trusted proxy IP addresses

$trustedProxies : array

Default

array()
 

Whether to use proxy addresses or not.

$useProxy : boolean

Default

false

As default this setting is disabled - IP address is mostly needed to increase security. HTTP_* are not reliable since can easily be spoofed. It can be enabled just for more flexibility, but if user uses proxy to connect to trusted services it's his/her own risk, only reliable field for IP address is $_SERVER['REMOTE_ADDR'].