drupal_goto

includes/common.inc, line 249

Versions
4.6 – 4.7
drupal_goto($path = '', $query = NULL, $fragment = NULL)
5 – 7
drupal_goto($path = '', $query = NULL, $fragment = NULL, $http_response_code = 302)

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.

See also

drupal_get_destination()

Parameters

$path A Drupal path or a full URL.

$query The query string component, if any.

$fragment The destination fragment identifier (named anchor).

▾ 29 functions call 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.
comment_reply in modules/comment.module
contact_admin_delete in modules/contact.module
Category delete page.
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().
filter_admin_delete in modules/filter.module
Menu callback; confirm deletion of a format.
legacy_blog_feed in modules/legacy.module
Menu callback; redirects users to new blog feed paths.
legacy_taxonomy_feed in modules/legacy.module
Menu callback; redirects users to new taxonomy feed paths.
legacy_taxonomy_page in modules/legacy.module
Menu callback; redirects users to new taxonomy page paths.
locale_admin_manage_delete_form in modules/locale.module
User interface for the language deletion confirmation screen.
menu_disable_confirm_submit in modules/menu.module
node_page in modules/node.module
Menu callback; dispatches control to the appropriate operation handler.
node_revision_delete in modules/node.module
Delete the revision with specified revision number. A "delete revision" nodeapi event is invoked when a revision is deleted.
node_revision_revert in modules/node.module
Revert to the revision with the specified revision number. A node and nodeapi "update" event is triggered (via the node_save() call) when a revision is reverted.
poll_vote in modules/poll.module
Callback for processing a vote
search_settings_form_validate in modules/search.module
Implementation of hook_validate().
search_view in modules/search.module
Menu callback; presents the search form and/or search results.
user_admin_access_add in modules/user.module
Menu callback: add an access rule
user_admin_access_edit in modules/user.module
Menu callback: edit an access rule
user_edit in modules/user.module
user_login in modules/user.module
user_logout in modules/user.module
Menu callback; logs the current user out, and redirects to the home page.
user_pass_reset in modules/user.module
Menu callback; process one time login link and redirects to the user page on success.
user_register in modules/user.module
_locale_string_delete in includes/locale.inc
Delete a language string.
_locale_string_edit in includes/locale.inc
User interface for string editing.

Code

<?php
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();
}
?>
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.