Documentation

HttpUtils
in package

Helps with common HTTP related tasks.

Tags
author

Derkades

version
2.0.0
license

MIT

Table of Contents

Properties

$_geoIpReader  : Reader

Methods

getHeader()  : string|null
Get header value.
getIpCountry()  : string
getPort()  : int|null
Get port used by client's HTTP request, using proxy headers if necessary.
getProtocol()  : string
Get the protocol used by client's HTTP request, using proxy headers if necessary.
getRemoteAddress()  : string|null
Get the client's true IP address, using proxy headers if necessary.
getTrustedProxies()  : array<string|int, mixed>
isTrustedProxiesConfigured()  : bool
Determine whether the trusted proxies config option is set to a valid value or not.
firstNonProxyAddress()  : string
Extract trustworthy address from a list of addresses provided by the Forwarded or X-Forwarded-For header.
isTrustedProxy()  : bool
Checks whether the client making the request is a trusted proxy.

Properties

$_geoIpReader

private static Reader $_geoIpReader

Methods

getHeader()

Get header value.

public static getHeader(string $header_name) : string|null
Parameters
$header_name : string

Header name

Return values
string|null

Header value, or null if header is not present in request

getIpCountry()

public static getIpCountry(string|null $ip) : string
Parameters
$ip : string|null
Return values
string

getPort()

Get port used by client's HTTP request, using proxy headers if necessary.

public static getPort() : int|null
Return values
int|null

Port number, or null when using the CLI

getProtocol()

Get the protocol used by client's HTTP request, using proxy headers if necessary.

public static getProtocol() : string
Return values
string

'http' if HTTP or 'https' if HTTPS. If the protocol is not known, for example when using the CLI, 'http' is always returned.

getRemoteAddress()

Get the client's true IP address, using proxy headers if necessary.

public static getRemoteAddress() : string|null
Return values
string|null

Client IP address, or null if there is no remote address, for example in CLI environment

getTrustedProxies()

public static getTrustedProxies() : array<string|int, mixed>
Return values
array<string|int, mixed>

List of trusted proxy networks according to config file and environment

isTrustedProxiesConfigured()

Determine whether the trusted proxies config option is set to a valid value or not.

public static isTrustedProxiesConfigured() : bool
Return values
bool

Whether the trusted proxies option is configured or not

firstNonProxyAddress()

Extract trustworthy address from a list of addresses provided by the Forwarded or X-Forwarded-For header.

private static firstNonProxyAddress(array<string|int, mixed> $addresses) : string
Parameters
$addresses : array<string|int, mixed>
Return values
string

Address that may be used for security purposes

isTrustedProxy()

Checks whether the client making the request is a trusted proxy.

private static isTrustedProxy() : bool
Return values
bool

Whether the client is a trusted proxy or not.


        
On this page

Search results