HumHub Documentation (unofficial)

RemoteAddress
in package

Functionality for determining client IP address.

Table of Contents

Properties

$proxyHeader  : string
HTTP header to introspect for proxies
$trustedProxies  : array<string|int, mixed>
List of trusted proxy IP addresses
$useProxy  : bool
Whether to use proxy addresses or not.

Methods

getIpAddress()  : string
Returns client IP address.
getUseProxy()  : bool
Checks proxy handling setting.
setProxyHeader()  : $this
Set the header to introspect for proxy IPs
setTrustedProxies()  : $this
Set list of trusted proxy addresses
setUseProxy()  : $this
Changes proxy handling setting.
getIpAddressFromProxy()  : false|string
Attempt to get the IP address for a proxied client
normalizeProxyHeader()  : string
Normalize a header string

Properties

$proxyHeader

HTTP header to introspect for proxies

protected string $proxyHeader = 'HTTP_X_FORWARDED_FOR'

$trustedProxies

List of trusted proxy IP addresses

protected array<string|int, mixed> $trustedProxies = []

$useProxy

Whether to use proxy addresses or not.

protected bool $useProxy = 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'].

Methods

getIpAddress()

Returns client IP address.

public getIpAddress() : string
Return values
string

IP address.

getUseProxy()

Checks proxy handling setting.

public getUseProxy() : bool
Return values
bool

Current setting value.

setProxyHeader()

Set the header to introspect for proxy IPs

public setProxyHeader([string $header = 'X-Forwarded-For' ]) : $this
Parameters
$header : string = 'X-Forwarded-For'
Return values
$this

setTrustedProxies()

Set list of trusted proxy addresses

public setTrustedProxies(array<string|int, mixed> $trustedProxies) : $this
Parameters
$trustedProxies : array<string|int, mixed>
Return values
$this

setUseProxy()

Changes proxy handling setting.

public setUseProxy([bool $useProxy = true ]) : $this

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

Parameters
$useProxy : bool = true

Whether to check also proxied IP addresses.

Return values
$this

normalizeProxyHeader()

Normalize a header string

protected normalizeProxyHeader(string $header) : string

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

Parameters
$header : string
Return values
string

        
On this page

Search results