Skip to content
Snippets Groups Projects
Commit 104fd02c authored by Olav Morken's avatar Olav Morken
Browse files

Utilities: Introduce normalizeURL().

This function normalizes the URL to an absolute URL, and makes sure
that it is a link to a http or https site.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@3008 44740490-163a-0410-bde0-09ae8108e29a
parent 5fc226b8
No related branches found
No related tags found
No related merge requests found
...@@ -1186,6 +1186,29 @@ class SimpleSAML_Utilities { ...@@ -1186,6 +1186,29 @@ class SimpleSAML_Utilities {
} }
/**
* Normalizes an URL to an absolute URL and validate it.
*
* In addition to resolving the URL, this function makes sure that it is
* a link to a http or https site.
*
* @param string $url The relative URL.
* @return string An absolute URL for the given relative URL.
*/
public static function normalizeURL($url) {
assert('is_string($url)');
$url = SimpleSAML_Utilities::resolveURL($url, SimpleSAML_Utilities::selfURL());
/* Verify that the URL is to a http or https site. */
if (!preg_match('@^https?://@i', $url)) {
throw new SimpleSAML_Error_Exception('Invalid URL: ' . $url);
}
return $url;
}
/** /**
* Parse a query string into an array. * Parse a query string into an array.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment