PHP Класс SimpleSAML\Utils\HTTP

Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
addURLParameters ( string $url, array $parameters ) : string Add one or more query parameters to the given URL.
checkSessionCookie ( string | null $retryURL = null ) : void Check for session cookie, and show missing-cookie page if it is missing.
checkURLAllowed ( string $url, array $trustedSites = null ) : string Check if a URL is valid and is in our list of allowed URLs.
fetch ( string $url, array $context = [], boolean $getHeaders = false ) : mixed Helper function to retrieve a file or URL with proxy support, also supporting proxy basic authorization.
getAcceptLanguage ( ) : array This function parses the Accept-Language HTTP header and returns an associative array with each language and the score for that language. If a language includes a region, then the result will include both the language with the region and the language without the region.
getBaseURL ( ) : string Retrieve the base URL of the SimpleSAMLphp installation. The URL will always end with a '/'. For example: https://idp.example.org/simplesaml/
getFirstPathElement ( boolean $trailingslash = true ) : string Retrieve the first element of the URL path.
getPOSTRedirectURL ( string $destination, array $data ) : string Create a link which will POST data.
getSelfHost ( ) : string Retrieve our own host.
getSelfHostWithNonStandardPort ( ) : string Retrieve our own host, including the port in case the it is not standard for the protocol in use. That is port 80 for HTTP and port 443 for HTTPS.
getSelfHostWithPath ( ) : string Retrieve our own host together with the URL path. Please note this function will return the base URL for the current SP, as defined in the global configuration.
getSelfURL ( ) : string Retrieve the current URL using the base URL in the configuration, if possible.
getSelfURLHost ( ) : string Retrieve the current URL using the base URL in the configuration, containing the protocol, the host and optionally, the port number.
getSelfURLNoQuery ( ) : string Retrieve the current URL using the base URL in the configuration, without the query parameters.
guessBasePath ( ) : string Try to guess the base SimpleSAMLphp path from the current request.
isHTTPS ( ) : boolean This function checks if we are using HTTPS as protocol.
normalizeURL ( string $url ) : string Normalizes a URL to an absolute URL and validate it. In addition to resolving the URL, this function makes sure that it is a link to an http or https site.
parseQueryString ( string $query_string ) : array Parse a query string into an array.
redirectTrustedURL ( string $url, string[] $parameters = [] ) : void This function redirects to the specified URL without performing any security checks. Please, do NOT use this function with user supplied URLs.
redirectUntrustedURL ( string $url, string[] $parameters = [] ) : void This function redirects to the specified URL after performing the appropriate security checks on it.
resolveURL ( string $url, string $base = null ) : string Resolve a (possibly relative) URL relative to a given base URL.
setCookie ( string $name, string | null $value, array | null $params = null, boolean $throw = true ) Set a cookie.
submitPOSTData ( string $destination, array $data ) Submit a POST form to a specific destination.

Приватные методы

Метод Описание
getSecurePOSTRedirectURL ( string $destination, array $data ) : string Obtain a URL where we can redirect to securely post a form with the given data to a specific destination.
getServerHTTPS ( ) : boolean Retrieve HTTPS status from $_SERVER environment variables.
getServerHost ( ) : string Retrieve Host value from $_SERVER environment variables.
getServerPort ( ) : string Retrieve the port number from $_SERVER environment variables.
redirect ( string $url, string[] $parameters = [] ) : void This function redirects the user to the specified address.
savePOSTData ( SimpleSAML_Session $session, string $destination, array $data ) : string Save the given HTTP POST data and the destination where it should be posted to a given session.

Описание методов

addURLParameters() публичный статический Метод

Add one or more query parameters to the given URL.
Автор: Andreas Solberg, UNINETT AS ([email protected])
Автор: Olav Morken, UNINETT AS ([email protected])
public static addURLParameters ( string $url, array $parameters ) : string
$url string The URL the query parameters should be added to.
$parameters array The query parameters which should be added to the url. This should be an associative array.
Результат string The URL with the new query parameters.

checkSessionCookie() публичный статический Метод

Check for session cookie, and show missing-cookie page if it is missing.
Автор: Olav Morken, UNINETT AS ([email protected])
public static checkSessionCookie ( string | null $retryURL = null ) : void
$retryURL string | null The URL the user should access to retry the operation. Defaults to null.
Результат void If there is a session cookie, nothing will be returned. Otherwise, the user will be redirected to a page telling about the missing cookie.

checkURLAllowed() публичный статический Метод

Check if a URL is valid and is in our list of allowed URLs.
Автор: Jaime Perez, UNINETT AS ([email protected])
public static checkURLAllowed ( string $url, array $trustedSites = null ) : string
$url string The URL to check.
$trustedSites array An optional white list of domains. If none specified, the 'trusted.url.domains' configuration directive will be used.
Результат string The normalized URL itself if it is allowed. An empty string if the $url parameter is empty as defined by the empty() function.

fetch() публичный статический Метод

. An exception will be thrown if we are unable to retrieve the data.
Автор: Andjelko Horvat
Автор: Olav Morken, UNINETT AS ([email protected])
Автор: Marco Ferrante, University of Genova ([email protected])
public static fetch ( string $url, array $context = [], boolean $getHeaders = false ) : mixed
$url string The path or URL we should fetch.
$context array Extra context options. This parameter is optional.
$getHeaders boolean Whether to also return response headers. Optional.
Результат mixed array if $getHeaders is set, string otherwise

getAcceptLanguage() публичный статический Метод

The returned array will be in the same order as the input.
Автор: Olav Morken, UNINETT AS ([email protected])
public static getAcceptLanguage ( ) : array
Результат array An associative array with each language and the score for that language.

getBaseURL() публичный статический Метод

Retrieve the base URL of the SimpleSAMLphp installation. The URL will always end with a '/'. For example: https://idp.example.org/simplesaml/
Автор: Olav Morken, UNINETT AS ([email protected])
public static getBaseURL ( ) : string
Результат string The absolute base URL for the SimpleSAMLphp installation.

getFirstPathElement() публичный статический Метод

Retrieve the first element of the URL path.
Автор: Andreas Solberg, UNINETT AS ([email protected])
public static getFirstPathElement ( boolean $trailingslash = true ) : string
$trailingslash boolean Whether to add a trailing slash to the element or not. Defaults to true.
Результат string The first element of the URL path, with an optional, trailing slash.

getPOSTRedirectURL() публичный статический Метод

Create a link which will POST data.
Автор: Andjelko Horvat
Автор: Jaime Perez, UNINETT AS ([email protected])
public static getPOSTRedirectURL ( string $destination, array $data ) : string
$destination string The destination URL.
$data array The name-value pairs which will be posted to the destination.
Результат string A URL which can be accessed to post the data.

getSelfHost() публичный статический Метод

E.g. www.example.com
Автор: Jaime Perez, UNINETT AS ([email protected])
public static getSelfHost ( ) : string
Результат string The current host.

getSelfHostWithNonStandardPort() публичный статический Метод

E.g. www.example.com:8080
Автор: Andreas Solberg, UNINETT AS ([email protected])
Автор: Olav Morken, UNINETT AS ([email protected])
public static getSelfHostWithNonStandardPort ( ) : string
Результат string The current host, followed by a colon and the port number, in case the port is not standard for the protocol.

getSelfHostWithPath() публичный статический Метод

Retrieve our own host together with the URL path. Please note this function will return the base URL for the current SP, as defined in the global configuration.
Автор: Andreas Solberg, UNINETT AS ([email protected])
Автор: Olav Morken, UNINETT AS ([email protected])
public static getSelfHostWithPath ( ) : string
Результат string The current host (with non-default ports included) plus the URL path.

getSelfURL() публичный статический Метод

This method will try to see if the current script is part of SimpleSAMLphp. In that case, it will use the 'baseurlpath' configuration option to rebuild the current URL based on that. If the current script is NOT part of SimpleSAMLphp, it will just return the current URL. Note that this method does NOT make use of the HTTP X-Forwarded-* set of headers.
Автор: Andreas Solberg, UNINETT AS ([email protected])
Автор: Olav Morken, UNINETT AS ([email protected])
Автор: Jaime Perez, UNINETT AS ([email protected])
public static getSelfURL ( ) : string
Результат string The current URL, including query parameters.

getSelfURLHost() публичный статический Метод

Retrieve the current URL using the base URL in the configuration, containing the protocol, the host and optionally, the port number.
Автор: Andreas Solberg, UNINETT AS ([email protected])
Автор: Olav Morken, UNINETT AS ([email protected])
public static getSelfURLHost ( ) : string
Результат string The current URL without path or query parameters.

getSelfURLNoQuery() публичный статический Метод

Retrieve the current URL using the base URL in the configuration, without the query parameters.
Автор: Andreas Solberg, UNINETT AS ([email protected])
Автор: Jaime Perez, UNINETT AS ([email protected])
public static getSelfURLNoQuery ( ) : string
Результат string The current URL, not including query parameters.

guessBasePath() публичный статический Метод

This method offers just a guess, so don't rely on it.
public static guessBasePath ( ) : string
Результат string The guessed base path that should correspond to the root installation of SimpleSAMLphp.

isHTTPS() публичный статический Метод

This function checks if we are using HTTPS as protocol.
Автор: Olav Morken, UNINETT AS ([email protected])
Автор: Jaime Perez, UNINETT AS ([email protected])
public static isHTTPS ( ) : boolean
Результат boolean True if the HTTPS is used, false otherwise.

normalizeURL() публичный статический Метод

Normalizes a URL to an absolute URL and validate it. In addition to resolving the URL, this function makes sure that it is a link to an http or https site.
Автор: Olav Morken, UNINETT AS ([email protected])
Автор: Jaime Perez, UNINETT AS ([email protected])
public static normalizeURL ( string $url ) : string
$url string The relative URL.
Результат string An absolute URL for the given relative URL.

parseQueryString() публичный статический Метод

This function parses a query string into an array, similar to the way the builtin 'parse_str' works, except it doesn't handle arrays, and it doesn't do "magic quotes". Query parameters without values will be set to an empty string.
Автор: Olav Morken, UNINETT AS ([email protected])
public static parseQueryString ( string $query_string ) : array
$query_string string The query string which should be parsed.
Результат array The query string as an associative array.

redirectTrustedURL() публичный статический Метод

This function will use the "HTTP 303 See Other" redirection if the current request used the POST method and the HTTP version is 1.1. Otherwise, a "HTTP 302 Found" redirection will be used. The function will also generate a simple web page with a clickable link to the target URL.
Автор: Jaime Perez, UNINETT AS ([email protected])
public static redirectTrustedURL ( string $url, string[] $parameters = [] ) : void
$url string The URL we should redirect to. This URL may include query parameters. If this URL is a relative URL (starting with '/'), then it will be turned into an absolute URL by prefixing it with the absolute URL to the root of the website.
$parameters string[] An array with extra query string parameters which should be appended to the URL. The name of the parameter is the array index. The value of the parameter is the value stored in the index. Both the name and the value will be urlencoded. If the value is NULL, then the parameter will be encoded as just the name, without a value.
Результат void This function never returns.

redirectUntrustedURL() публичный статический Метод

Particularly, it will make sure that the provided URL is allowed by the 'redirect.trustedsites' directive in the configuration. If the aforementioned option is not set or the URL does correspond to a trusted site, it performs a redirection to it. If the site is not trusted, an exception will be thrown.
Автор: Jaime Perez, UNINETT AS ([email protected])
public static redirectUntrustedURL ( string $url, string[] $parameters = [] ) : void
$url string The URL we should redirect to. This URL may include query parameters. If this URL is a relative URL (starting with '/'), then it will be turned into an absolute URL by prefixing it with the absolute URL to the root of the website.
$parameters string[] An array with extra query string parameters which should be appended to the URL. The name of the parameter is the array index. The value of the parameter is the value stored in the index. Both the name and the value will be urlencoded. If the value is NULL, then the parameter will be encoded as just the name, without a value.
Результат void This function never returns.

resolveURL() публичный статический Метод

This function supports these forms of relative URLs: - ^\w+: Absolute URL. E.g. "http://www.example.com:port/path?query#fragment". - ^// Same protocol. E.g. "//www.example.com:port/path?query#fragment" - ^/ Same protocol and host. E.g. "/path?query#fragment". - ^? Same protocol, host and path, replace query string & fragment. E.g. "?query#fragment". - ^# Same protocol, host, path and query, replace fragment. E.g. "#fragment". - The rest: Relative to the base path.
Автор: Olav Morken, UNINETT AS ([email protected])
Автор: Jaime Perez, UNINETT AS ([email protected])
public static resolveURL ( string $url, string $base = null ) : string
$url string The relative URL.
$base string The base URL. Defaults to the base URL of this installation of SimpleSAMLphp.
Результат string An absolute URL for the given relative URL.

setCookie() публичный статический Метод

Set a cookie.
Автор: Andjelko Horvat
Автор: Jaime Perez, UNINETT AS ([email protected])
public static setCookie ( string $name, string | null $value, array | null $params = null, boolean $throw = true )
$name string The name of the cookie.
$value string | null The value of the cookie. Set to NULL to delete the cookie.
$params array | null Cookie parameters.
$throw boolean Whether to throw exception if setcookie() fails.

submitPOSTData() публичный статический Метод

This function never returns.
Автор: Olav Morken, UNINETT AS ([email protected])
Автор: Andjelko Horvat
Автор: Jaime Perez, UNINETT AS ([email protected])
public static submitPOSTData ( string $destination, array $data )
$destination string The destination URL.
$data array An associative array with the data to be posted to $destination.