public static function redirect($url, $parameters = array(), $stay = false)
{
assert('is_string($url)');
assert('is_array($parameters)');
if (substr($url, 0, 1) === '/') {
$url = self::getSelfURLhost() . $url;
}
/* Verify that the URL is to a http or https site. */
if (!preg_match('@^https?:\\/\\/@i', $url)) {
throw new OneLogin_Saml2_Error('Redirect to invalid URL: ' . $url, OneLogin_Saml2_Error::REDIRECT_INVALID_URL);
}
/* Add encoded parameters */
if (strpos($url, '?') === false) {
$paramPrefix = '?';
} else {
$paramPrefix = '&';
}
foreach ($parameters as $name => $value) {
if ($value === null) {
$param = urlencode($name);
} else {
if (is_array($value)) {
$param = "";
foreach ($value as $val) {
$param .= urlencode($name) . "[]=" . urlencode($val) . '&';
}
if (!empty($param)) {
$param = substr($param, 0, -1);
}
} else {
$param = urlencode($name) . '=' . urlencode($value);
}
}
if (!empty($param)) {
$url .= $paramPrefix . $param;
$paramPrefix = '&';
}
}
if ($stay) {
return $url;
}
header('Pragma: no-cache');
header('Cache-Control: no-cache, must-revalidate');
header('Location: ' . $url);
exit;
}