drupal_goto

Versions
4.6 – 4.7
drupal_goto($path = '', $query = NULL, $fragment = NULL)
5 – 6
drupal_goto($path = '', $query = NULL, $fragment = NULL, $http_response_code = 302)
7
drupal_goto($path = '', array $options = array(), $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.

It is advised to use drupal_goto() instead of PHP's header(), because drupal_goto() will append the user's session ID to the URI when PHP is compiled with "--enable-trans-sid".

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.

$query The query string component, if any.

$fragment The destination fragment identifier (named anchor).

▾ 62 functions call drupal_goto()

aggregator_admin_edit_category in modules/aggregator.module
Menu callback; displays the category edit form, or saves changes and redirects to the overview page.
aggregator_admin_edit_feed in modules/aggregator.module
Menu callback; displays the feed edit form.
aggregator_admin_refresh_feed in modules/aggregator.module
Menu callback; refreshes a feed, then redirects to the overview page.
aggregator_admin_remove_feed in modules/aggregator.module
Menu callback; removes all items from a feed, then redirects to the overview page.
aggregator_edit in modules/aggregator.module
block_admin in modules/block.module
Menu callback; displays the block overview page.
block_admin_configure in modules/block.module
Menu callback; displays the block configuration form.
block_box_add in modules/block.module
Menu callback; displays the block creation form.
block_box_delete in modules/block.module
Menu callback; confirm and delete custom blocks.
book_outline in modules/book.module
Implementation of function book_outline() Handles all book outline operations.
comment_admin_edit in modules/comment.module
Menu callback; edit a comment from the administrative interface.
comment_delete in modules/comment.module
Menu callback; delete a comment.
comment_post in modules/comment.module
comment_reply in modules/comment.module
comment_save_settings in modules/comment.module
contact_mail_user in modules/contact.module
filter_admin_add in modules/filter.module
Add a new input format.
filter_admin_delete in modules/filter.module
Menu callback; confirm deletion of a format.
filter_admin_filters_save in modules/filter.module
Save enabled/disabled status for filters in a format.
filter_admin_order_save in modules/filter.module
Save the weights of filters in a format.
filter_admin_save in modules/filter.module
Save input formats on the overview page.
forum_admin in modules/forum.module
Administration page which allows maintaining forums
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_import in modules/locale.module
Page handler for the translation import screen
locale_admin_manage in modules/locale.module
Page handler for the language management screen
locale_admin_manage_add in modules/locale.module
Page handler for the language addition screen
locale_admin_manage_delete_screen in modules/locale.module
User interface for the language deletion confirmation screen
locale_admin_string in modules/locale.module
Page handler for the string search and administration screen
menu_add_menu in modules/menu.module
Menu callback; handle the adding of a new menu.
menu_delete_item in modules/menu.module
Menu callback; delete a single custom item.
menu_disable_item in modules/menu.module
Menu callback; hide a menu item.
menu_edit_item in modules/menu.module
Menu callback; dispatch to the appropriate menu item edit function.
menu_reset in modules/menu.module
Menu callback; clear the database, resetting the menu to factory defaults.
menu_reset_item in modules/menu.module
Menu callback; reset a single modified item.
node_admin_nodes in modules/node.module
Generate the content administration overview.
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.
node_revision_rollback in modules/node.module
Roll back to the revision with the specified revision number.
path_admin_delete in modules/path.module
Menu callback; handles deletion of an URL alias.
path_save in modules/path.module
Verify that a new URL alias is valid, and save it to the database.
poll_vote in modules/poll.module
Callback for processing a vote
profile_admin_add in modules/profile.module
Menu callback; adds a new field to all user profiles.
profile_admin_delete in modules/profile.module
Menu callback; deletes a field from all user profiles.
profile_admin_edit in modules/profile.module
Menu callback; displays the profile field editing form.
search_view in modules/search.module
Menu callback; presents the search form and/or search results.
system_listing_save in modules/system.module
system_settings_save in modules/system.module
taxonomy_admin in modules/taxonomy.module
Menu callback; dispatches to the proper taxonomy administration function.
user_admin_access_add in modules/user.module
Menu callback: add an access rule
user_admin_access_delete in modules/user.module
Menu callback: delete an access rule
user_admin_access_edit in modules/user.module
Menu callback: edit an access rule
user_admin_perm in modules/user.module
Menu callback: administer permissions.
user_admin_role in modules/user.module
Menu callback: administer roles.
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_page in modules/user.module
user_pass in modules/user.module
user_register in modules/user.module
_aggregator_page_list in modules/aggregator.module
Prints an aggregator page listing a number of feed items. Various menu callbacks use this function to print their feeds.

Code

includes/common.inc, line 167

<?php
function drupal_goto($path = '', $query = NULL, $fragment = NULL) {
  if ($_REQUEST['destination']) {
    extract(parse_url($_REQUEST['destination']));
  }
  else if ($_REQUEST['edit']['destination']) {
    extract(parse_url($_REQUEST['edit']['destination']));
  }

  $url = url($path, $query, $fragment, TRUE);

  if (ini_get('session.use_trans_sid') && session_id() && !strstr($url, session_id())) {
    $sid = session_name() . '=' . session_id();

    if (strstr($url, '?') && !strstr($url, $sid)) {
      $url = $url .'&'. $sid;
    }
    else {
      $url = $url .'?'. $sid;
    }
  }

  // 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();
}
?>
Login or register to post comments
 
 

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.