HTTP request helpers.
More...
|
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...
|
|
HTTP request helpers.
Definition at line 8 of file Http.php.
◆ addParams()
static addParams |
( |
|
$url, |
|
|
|
$params |
|
) |
| |
|
static |
Add parameters to a URL.
- Parameters
-
string | $url | Base URL. |
mixed | $params | Array 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 | $code | HTTP response code. |
- Returns
- string Description (null if not found).
Definition at line 69 of file Http.php.
◆ docRoot()
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 | $filename | Filename of the attached file. |
string | $content_type | Content type (defaults to 'application/' + extension of filename). |
int | $size | Size 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 | $url | Base URL. |
string | $protocol | Protocol 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 | $addr | Basic 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 | $key | Cookie key. |
mixed | $default | Default 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 | $complete | Include 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 | $subnets | One or more subnet(s) in CIDR notation (e.g. 127.0.0.0/24). |
string | $remote_addr | The 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 | $accepted | Accepted languages (with or without locale; empty = all). |
float | $quality | Minimal quality a language must have. |
- Returns
- string Language preference (empty = none found).
Definition at line 154 of file Http.php.
◆ method()
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 | $size | Size of POST. |
int | $max | Maximum size. |
- Returns
- bool
Definition at line 111 of file Http.php.
◆ pushHeader()
static pushHeader |
( |
|
$src, |
|
|
|
$type |
|
) |
| |
|
static |
Add a push header.
- Parameters
-
string | $src | Location of the resource. |
string | $type | Type 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()
Remove double dots from a URL.
- Parameters
-
- 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 | $url | URL to redirect to. |
bool | $permanent | True to make the redirection permanent (HTTP code 301; defaul is 302). |
Definition at line 223 of file Http.php.
◆ remoteAddr()
Returns the expanded, remote address (if available).
- Returns
- string
Definition at line 191 of file Http.php.
◆ secure()
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 | $key | Cookie key. |
mixed | $value | Cookie value. |
int | $days | Cookie lifetime (in days). |
array | $options | Cookie 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 | $url | URL to make request to. |
array | $post | Data to post with request (key => value pairs). |
array | $headers | Extra HTTP headers to add to request (key = header name, value = header value). |
array | $options | Extra cURL options (key = option name, value = option value). |
int | $timeout | Request timeout in seconds. |
int | $max_redirs | Maximum 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()
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:
- /var/www/fred.local/vendor/rsi/helpers/src/Rsi/Http.php