class Forwarded (View source)

Constants

IP

PROTO

HOST

PREFIX

RFC7239

DEFAULT_SOURCES

VALID_SOURCES

IPV4_MAPPED_PREFIX

REGEX_RFC7239

Methods

__construct(array $server, int|null $code = 403)

Creates a new instance

setKnownNetworks(array $networks)

Sets the address ranges (CIDR notation, IPv4 or IPv6) of proxies

setKnownProxies(array $proxies)

Sets the exact addresses of proxies from which forwarded headers are accepted

setAllowedHosts(array $hosts)

Sets the hosts accepted when the host comes from a forwarded header. Supported patterns:

  • example.com
  • *.example.com
  • * (any host)

setFlags(int $flags)

Set the headers that must/may provide values

setHeaderName(int $flag, string $name)

Set the headers names

setLimit(int $limit)

Sets how many trusted proxies are in front of the application.

string|null
getIp()

Get IP

string
getProto()

Get protocol/scheme (https or http)

string|null
getHost()

Get host

string
getPrefix()

Get prefix

Details

__construct(array $server, int|null $code = 403)

Creates a new instance

Parameters

array $server

Server variables, usually $_SERVER

int|null $code

Response code (4xx) when the request is not from a known proxy (null to disable)

Exceptions

Exception

setKnownNetworks(array $networks)

Sets the address ranges (CIDR notation, IPv4 or IPv6) of proxies

Parameters

array $networks

setKnownProxies(array $proxies)

Sets the exact addresses of proxies from which forwarded headers are accepted

Parameters

array $proxies

setAllowedHosts(array $hosts)

Sets the hosts accepted when the host comes from a forwarded header. Supported patterns:

  • example.com
  • *.example.com
  • * (any host)

Note: entries must be in non-transitional IDNA (UTS #46) ASCII format

Parameters

array $hosts

setFlags(int $flags)

Set the headers that must/may provide values

Parameters

int $flags

Exceptions

Exception

setHeaderName(int $flag, string $name)

Set the headers names

Parameters

int $flag
string $name

Exceptions

Exception

setLimit(int $limit)

Sets how many trusted proxies are in front of the application.

In headers with comma-separated values (e.g. X-Forwarded-For, or multiple Forwarded: entries) the value is taken counting from the end of the list: 1 (default) uses the last entry (appended by the closest proxy), 2 the second to last, and so on. If the limit is greater than the number of entries, the first one is used. This prevents clients from spoofing values at the beginning of the list.

Parameters

int $limit

string|null getIp()

Get IP

Return Value

string|null

string getProto()

Get protocol/scheme (https or http)

Return Value

string

string|null getHost()

Get host

Return Value

string|null

string getPrefix()

Get prefix

Return Value

string