function path_redirect_goto in Path redirect 5
Same name and namespace in other branches
- 6 path_redirect.module \path_redirect_goto()
This is a copy of drupal_goto() redesigned for use during the bootstrap
File
- ./
path_redirect.module, line 574
Code
function path_redirect_goto($path = '', $query = NULL, $fragment = NULL, $http_response_code = 302) {
$url = $path;
// Make the given path or URL absolute
if (!preg_match('/^[a-z]+:\\/\\//', $url)) {
global $base_url;
$url = $base_url . '/' . $url;
}
$url .= empty($query) ? '' : '?' . $query;
$url .= empty($fragment) ? '' : '#' . $fragment;
// Remove newlines from the URL to avoid header injection attacks.
$url = str_replace(array(
"\n",
"\r",
), '', $url);
// Before the redirect, allow modules to react to the end of the page request.
bootstrap_invoke_all('exit');
// Even though session_write_close() is registered as a shutdown function, we
// need all session data written to the database before redirecting.
session_write_close();
header('Location: ' . $url, TRUE, $http_response_code);
// The "Location" header sends a REDIRECT status code to the http
// daemon. In some cases this can go wrong, so we make sure none
// of the code below the drupal_goto() call gets executed when we redirect.
exit;
}