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

Utilities: Updated addURLparameter to merge the new query string with the old query string.

This should fix a problem where one can end up with multiple parameters with
the same name in the query string. This patch also changes the $parameter of
addURLparameter to be an associative array. For backwards compatibility it can
still be a string.


git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@739 44740490-163a-0410-bde0-09ae8108e29a
parent 4bec7c26
No related branches found
No related tags found
No related merge requests found
...@@ -134,15 +134,41 @@ class SimpleSAML_Utilities { ...@@ -134,15 +134,41 @@ class SimpleSAML_Utilities {
} }
return $requesturi; return $requesturi;
} }
/**
* Add one or more query parameters to the given URL.
*
* @param $url The URL the query parameters should be added to.
* @param $parameter The query parameters which should be added to the url. This should be
* an associative array. For backwards comaptibility, it can also be a
* query string representing the new parameters.
* @return The URL with the new query parameters.
*/
public static function addURLparameter($url, $parameter) { public static function addURLparameter($url, $parameter) {
if (strstr($url, '?')) {
return $url . '&' . $parameter; /* For backwards compatibility - allow $parameter to be a string. */
if(is_string($parameter)) {
$parameter = self::parseQueryString($parameter);
}
assert('is_array($parameter)');
$queryStart = strpos($url, '?');
if($queryStart === FALSE) {
$oldQuery = array();
$url .= '?';
} else { } else {
return $url . '?' . $parameter; $oldQuery = self::parseQueryString(substr($url, $queryStart + 1));
$url = substr($url, 0, $queryStart + 1);
} }
$query = array_merge($oldQuery, $parameter);
$url .= http_build_query($query);
return $url;
} }
public static function strleft($s1, $s2) { public static function strleft($s1, $s2) {
return substr($s1, 0, strpos($s1, $s2)); return substr($s1, 0, strpos($s1, $s2));
} }
......
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