drupal_goto($path = '', $query = NULL, $fragment = NULL, $http_response_code = 302)
drupal/includes/common.inc, line 325
Send the user to a different Drupal page.
This issues an on-site HTTP redirect. The function makes sure the redirected URL is formatted correctly.
Usually the redirected URL is constructed from this function's input parameters. However you may override that behavior by setting a destination in either the $_REQUEST-array (i.e. by using the query string of an URI) This is used to direct the user back to the proper page after completing a form. For example, after editing a post on the 'admin/content/node'-page or after having logged on using the 'user login'-block in a sidebar. The function drupal_get_destination() can be used to help set the destination URL.
Drupal will ensure that messages set by drupal_set_message() and other session data are written to the database before the user is redirected.
This function ends the request; use it rather than a print theme('page') statement in your menu callback.
@see drupal_get_destination()
$path A Drupal path or a full URL.
$query A query string component, if any.
$fragment A destination fragment identifier (named anchor).
$http_response_code Valid values for an actual "goto" as per RFC 2616 section 10.3 are:
function drupal_goto($path = '', $query = NULL, $fragment = NULL, $http_response_code = 302) {
if (isset($_REQUEST['destination'])) {
extract(parse_url(urldecode($_REQUEST['destination'])));
}
$url = url($path, array('query' => $query, 'fragment' => $fragment, 'absolute' => TRUE));
// Remove newlines from the URL to avoid header injection attacks.
$url = str_replace(array("\n", "\r"), '', $url);
// Allow modules to react to the end of the page request before redirecting.
// We do not want this while running update.php.
if (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update') {
module_invoke_all('exit', $url);
}
// 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 be wrong, so we make sure none of the code below the
// drupal_goto() call gets executed upon redirection.
exit();
}