RSI helpers  0.1
RSI helpers
Http Class Reference

HTTP request helpers. More...

Static Public Member Functions

static docRoot ()
 Document root. More...
 
static version ()
 Protocol version. More...
 
static method ()
 Request method. More...
 
static secure ()
 Check if the request was made over a secure connection. More...
 
static host ($complete=false)
 Host name. More...
 
static codeDescr ($code)
 Translate a HTTP response code to a description. More...
 
static ensureProtocol ($url, $protocol='http')
 Make sure a URL starts with a protocol. More...
 
static realUrl ($url)
 Remove double dots from a URL. More...
 
static addParams ($url, $params)
 Add parameters to a URL. More...
 
static postExceeded (&$size=null, &$max=null)
 Check if the maximum POST size was exceeded. More...
 
static setCookie ($key, $value, $days=365, $options=null)
 Set a cookie. More...
 
static getCookie ($key, $default=null)
 Retrieve a cookie. More...
 
static lang ($accepted=null, $quality=0)
 Get the prefered language from the client. More...
 
static expandAddr ($addr)
 Expand an abbreviated IPv6 address to its full representation. More...
 
static remoteAddr ()
 Returns the expanded, remote address (if available). More...
 
static inSubnet ($subnets, $remote_addr=null)
 Check if an IP-adres lies within a certain subnet. More...
 
static redirHeader ($url, $permanent=false)
 Add a redirection header. More...
 
static pushHeader ($src, $type)
 Add a push header. More...
 
static downloadHeaders ($filename, $content_type=null, $size=null)
 Send download headers. More...
 
static urlGetContents ($url, $post=null, $headers=null, $options=null, $timeout=null, $max_redirs=null)
 Get content from URL. More...
 

Detailed Description

HTTP request helpers.

Definition at line 8 of file Http.php.

Member Function Documentation

◆ addParams()

static addParams (   $url,
  $params 
)
static

Add parameters to a URL.

Parameters
string$urlBase URL.
mixed$paramsArray will beconverted to string.
Returns
string URL with parameters added.

Definition at line 97 of file Http.php.

◆ codeDescr()

static codeDescr (   $code)
static

Translate a HTTP response code to a description.

Parameters
int$codeHTTP response code.
Returns
string Description (null if not found).

Definition at line 69 of file Http.php.

◆ docRoot()

static docRoot ( )
static

Document root.

Returns
string Document root without trailing delimiter.

Definition at line 14 of file Http.php.

◆ downloadHeaders()

static downloadHeaders (   $filename,
  $content_type = null,
  $size = null 
)
static

Send download headers.

Parameters
string$filenameFilename of the attached file.
string$content_typeContent type (defaults to 'application/' + extension of filename).
int$sizeSize of the download (gives user progress indication).

Definition at line 242 of file Http.php.

◆ ensureProtocol()

static ensureProtocol (   $url,
  $protocol = 'http' 
)
static

Make sure a URL starts with a protocol.

Add one if not present.

Parameters
string$urlBase URL.
string$protocolProtocol to add if none present.
Returns
string URL with protocol.

Definition at line 78 of file Http.php.

◆ expandAddr()

static expandAddr (   $addr)
static

Expand an abbreviated IPv6 address to its full representation.

Parameters
string$addrBasic address.
Returns
string Expanded address (IPv4 addresses are untouched).

Definition at line 178 of file Http.php.

◆ getCookie()

static getCookie (   $key,
  $default = null 
)
static

Retrieve a cookie.

Parameters
string$keyCookie key.
mixed$defaultDefault value if the key does not exist.
Returns
mixed Found value, or default value if the key does not exist.

Definition at line 145 of file Http.php.

◆ host()

static host (   $complete = false)
static

Host name.

Parameters
bool$completeInclude protocol and port number.
Returns
string

Definition at line 56 of file Http.php.

◆ inSubnet()

static inSubnet (   $subnets,
  $remote_addr = null 
)
static

Check if an IP-adres lies within a certain subnet.

Parameters
string | array$subnetsOne or more subnet(s) in CIDR notation (e.g. 127.0.0.0/24).
string$remote_addrThe IP-address to check (defaults to remoteAddr()).
Returns
bool

Definition at line 202 of file Http.php.

◆ lang()

static lang (   $accepted = null,
  $quality = 0 
)
static

Get the prefered language from the client.

Parameters
array$acceptedAccepted languages (with or without locale; empty = all).
float$qualityMinimal quality a language must have.
Returns
string Language preference (empty = none found).

Definition at line 154 of file Http.php.

◆ method()

static method ( )
static

Request method.

Returns
string Requested method, in uppercase.

Definition at line 41 of file Http.php.

◆ postExceeded()

static postExceeded ( $size = null,
$max = null 
)
static

Check if the maximum POST size was exceeded.

Parameters
int$sizeSize of POST.
int$maxMaximum size.
Returns
bool

Definition at line 111 of file Http.php.

◆ pushHeader()

static pushHeader (   $src,
  $type 
)
static

Add a push header.

Parameters
string$srcLocation of the resource.
string$typeType of the resource.
Returns
bool True if push is supported and the header is set, false otherwise.

Definition at line 232 of file Http.php.

◆ realUrl()

static realUrl (   $url)
static

Remove double dots from a URL.

Parameters
string$urlBase URL.
Returns
string URL with double dots removed (including the directory before it).

Definition at line 86 of file Http.php.

◆ redirHeader()

static redirHeader (   $url,
  $permanent = false 
)
static

Add a redirection header.

Parameters
string$urlURL to redirect to.
bool$permanentTrue to make the redirection permanent (HTTP code 301; defaul is 302).

Definition at line 223 of file Http.php.

◆ remoteAddr()

static remoteAddr ( )
static

Returns the expanded, remote address (if available).

Returns
string

Definition at line 191 of file Http.php.

◆ secure()

static secure ( )
static

Check if the request was made over a secure connection.

Returns
bool True if the request was made over a secure connection.

Definition at line 48 of file Http.php.

◆ setCookie()

static setCookie (   $key,
  $value,
  $days = 365,
  $options = null 
)
static

Set a cookie.

The cookie is also directly added to the global $_COOKIE array.

Parameters
string$keyCookie key.
mixed$valueCookie value.
int$daysCookie lifetime (in days).
array$optionsCookie options (see https://www.php.net/setcookie; when 'secure' is undefined, the value is automaticly set to true when the request was made using a secure connection).
Returns
bool True when successful.

Definition at line 130 of file Http.php.

◆ urlGetContents()

static urlGetContents (   $url,
  $post = null,
  $headers = null,
  $options = null,
  $timeout = null,
  $max_redirs = null 
)
static

Get content from URL.

Parameters
string$urlURL to make request to.
array$postData to post with request (key => value pairs).
array$headersExtra HTTP headers to add to request (key = header name, value = header value).
array$optionsExtra cURL options (key = option name, value = option value).
int$timeoutRequest timeout in seconds.
int$max_redirsMaximum number of redirections to follow.
Returns
mixed Response text if susccessful (200) or false if not found (404). Exceptions thrown on cURL error or other response codes.

Definition at line 262 of file Http.php.

◆ version()

static version ( )
static

Protocol version.

Returns
float Protocol version (false if unknown).

Definition at line 30 of file Http.php.


The documentation for this class was generated from the following file: