private static function redirect($url, $parameters = array())
{
if (!is_string($url) || empty($url) || !is_array($parameters)) {
throw new \InvalidArgumentException('Invalid input parameters.');
}
if (!empty($parameters)) {
$url = self::addURLParameters($url, $parameters);
}
/* Set the HTTP result code. This is either 303 See Other or
* 302 Found. HTTP 303 See Other is sent if the HTTP version
* is HTTP/1.1 and the request type was a POST request.
*/
if ($_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1' && $_SERVER['REQUEST_METHOD'] === 'POST') {
$code = 303;
} else {
$code = 302;
}
if (strlen($url) > 2048) {
Logger::warning('Redirecting to a URL longer than 2048 bytes.');
}
if (!headers_sent()) {
// set the location header
header('Location: ' . $url, true, $code);
// disable caching of this response
header('Pragma: no-cache');
header('Cache-Control: no-cache, must-revalidate');
}
// show a minimal web page with a clickable link to the URL
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"';
echo ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' . "\n";
echo '<html xmlns="http://www.w3.org/1999/xhtml">' . "\n";
echo " <head>\n";
echo ' <meta http-equiv="content-type" content="text/html; charset=utf-8">' . "\n";
echo " <title>Redirect</title>\n";
echo " </head>\n";
echo " <body onload=\"window.location.replace('" . htmlspecialchars($url) . "');\">\n";
echo " <h1>Redirect</h1>\n";
echo ' <p>You were redirected to: <a id="redirlink" href="' . htmlspecialchars($url) . '">';
echo htmlspecialchars($url) . "</a>\n";
echo ' <script type="text/javascript">document.getElementById("redirlink").focus();</script>' . "\n";
echo " </p>\n";
echo " </body>\n";
echo '</html>';
// end script execution
exit;
}