You are here

function drupal_goto in Drupal 4

Same name and namespace in other branches
  1. 5 includes/common.inc \drupal_goto()
  2. 6 includes/common.inc \drupal_goto()
  3. 7 includes/common.inc \drupal_goto()

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 <em>destination</em> in either the $_REQUEST-array (i.e. by using the query string of an URI) or the $_REQUEST['edit']-array (i.e. by using a hidden form field). 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/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.

This function ends the request; use it rather than a print theme('page') statement in your menu callback.

Parameters

$path: A Drupal path or a full URL.

$query: The query string component, if any.

$fragment: The destination fragment identifier (named anchor).

See also

drupal_get_destination()

29 calls to drupal_goto()
aggregator_admin_refresh_feed in modules/aggregator.module
Menu callback; refreshes a feed, then redirects to the overview page.
comment_admin_overview_submit in modules/comment.module
Execute the chosen 'Update option' on the selected comments, such as publishing, unpublishing or deleting.
comment_admin_overview_validate in modules/comment.module
We can't execute any 'Update options' if no comments were selected.
comment_multiple_delete_confirm in modules/comment.module
List the selected comments and verify that the admin really wants to delete them.
comment_multiple_delete_confirm_submit in modules/comment.module
Perform the actual comment deletion.

... See full list

2 string references to 'drupal_goto'
drupal_get_form in includes/form.inc
Processes a form array and produces the HTML output of a form. If there is input in the $_POST['edit'] variable, this function will attempt to validate it, using drupal_validate_form(), and then submit the form using drupal_submit_form().
legacy_menu in modules/legacy.module
Implementation of hook_menu().

File

includes/common.inc, line 249
Common functions that many Drupal modules will need to reference.

Code

function drupal_goto($path = '', $query = NULL, $fragment = NULL) {
  if (isset($_REQUEST['destination'])) {
    extract(parse_url(urldecode($_REQUEST['destination'])));
  }
  else {
    if (isset($_REQUEST['edit']['destination'])) {
      extract(parse_url(urldecode($_REQUEST['edit']['destination'])));
    }
  }
  $url = url($path, $query, $fragment, TRUE);

  // 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.
  module_invoke_all('exit', $url);
  header('Location: ' . $url);

  // 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;
}