drupal_goto

  1. drupal
    1. 5
    2. 6
    3. 7
    4. 8
Versions
5 – 6 drupal_goto($path = '', $query = NULL, $fragment = NULL, $http_response_code = 302)
8 – 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 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'-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 instead of a return in your menu callback.

Parameters

$path A Drupal path or a full URL.

$options An associative array of additional URL options to pass to url().

$http_response_code Valid values for an actual "goto" as per RFC 2616 section 10.3 are:

  • 301 Moved Permanently (the recommended value for most redirects)
  • 302 Found (default in Drupal and PHP, sometimes used for spamming search engines)
  • 303 See Other
  • 304 Not Modified
  • 305 Use Proxy
  • 307 Temporary Redirect (alternative to "503 Site Down for Maintenance")

Note: Other values are defined by RFC 2616, but are rarely used and poorly supported.

See also

drupal_get_destination()

url()

Related topics

▾ 44 functions call drupal_goto()

aggregator_admin_refresh_feed in modules/aggregator/aggregator.admin.inc
Menu callback; refreshes a feed, then redirects to the overview page.
comment_approve in modules/comment/comment.pages.inc
Menu callback; publish specified comment.
comment_multiple_delete_confirm in modules/comment/comment.admin.inc
List the selected comments and verify that the admin wants to delete them.
comment_reply in modules/comment/comment.pages.inc
This function is responsible for generating a comment reply form. There are several cases that have to be handled, including:
common_test_drupal_goto_redirect in modules/simpletest/tests/common_test.module
Redirect using drupal_goto().
common_test_drupal_goto_redirect_advanced in modules/simpletest/tests/common_test.module
Redirect using drupal_goto().
drupal_redirect_form in includes/form.inc
Redirects the user to a URL after a form has been processed.
image_effect_form in modules/image/image.admin.inc
Form builder; Form for adding and editing image effects.
locale_languages_delete_form in modules/locale/locale.admin.inc
User interface for the language deletion confirmation screen.
locale_translate_edit_form in modules/locale/locale.admin.inc
User interface for string editing.
node_add_page in modules/node/node.pages.inc
openid_authentication in modules/openid/openid.module
Authenticate a user or attempt registration.
openid_authentication_page in modules/openid/openid.pages.inc
Menu callback; Process an OpenID authentication.
overlay_init in modules/overlay/overlay.module
Implements hook_init().
overlay_user_dismiss_message in modules/overlay/overlay.module
Menu callback; dismisses the overlay accessibility message for this user.
search_view in modules/search/search.pages.inc
Menu callback; presents the search form and/or search results.
shortcut_link_add_inline in modules/shortcut/shortcut.admin.inc
Menu page callback: creates a new link in the provided shortcut set.
simpletest_result_form in modules/simpletest/simpletest.pages.inc
Test results form for $test_id.
system_actions_configure in modules/system/system.admin.inc
Menu callback; Creates the form for configuration of a single action.
system_actions_remove_orphans in modules/system/system.admin.inc
Remove actions that are in the database but not supported by any enabled module.
system_admin_compact_page in modules/system/system.module
Menu callback; Sets whether the admin menu is in compact mode or not.
system_authorized_run in modules/system/system.module
Setup and invoke an operation using authorize.php.
system_goto_action in modules/system/system.module
Redirects to a different URL.
system_modules_uninstall_validate in modules/system/system.admin.inc
Validates the submitted uninstall form.
system_run_cron in modules/system/system.admin.inc
Menu callback: run cron manually.
system_run_cron_submit in modules/system/system.admin.inc
Submit callback; run cron.
system_test_authorize_init_page in modules/simpletest/tests/system_test.module
Page callback to initialize authorize.php during testing.
system_theme_default in modules/system/system.admin.inc
Menu callback; Set the default theme.
system_theme_disable in modules/system/system.admin.inc
Menu callback; Disables a theme.
system_theme_enable in modules/system/system.admin.inc
Menu callback; Enables a theme.
toolbar_toggle_page in modules/toolbar/toolbar.module
Menu callback; toggles the visibility of the toolbar drawer.
trigger_assign in modules/trigger/trigger.admin.inc
Builds the form that allows users to assign actions to triggers.
trigger_unassign in modules/trigger/trigger.admin.inc
Confirm removal of an assigned action.
trigger_unassign_submit in modules/trigger/trigger.admin.inc
Submit callback for trigger_unassign() form.
update_manager_download_batch_finished in modules/update/update.manager.inc
Batch callback invoked when the download batch is completed.
user_admin_role in modules/user/user.admin.inc
Form to configure a single role.
user_cancel_confirm in modules/user/user.pages.inc
Menu callback; Cancel a user account via e-mail confirmation link.
user_login in modules/user/user.module
Form builder; the main user login form.
user_logout in modules/user/user.pages.inc
Menu callback; logs the current user out, and redirects to the home page.
user_menu_site_status_alter in modules/user/user.module
Implements hook_menu_site_status_alter().
user_multiple_cancel_confirm in modules/user/user.module
user_pass_reset in modules/user/user.pages.inc
Menu callback; process one time login link and redirects to the user page on success.
user_register_form in modules/user/user.module
Form builder; the user registration form.
_batch_page in includes/batch.inc
State-based dispatcher for the batch processing page.

Code

includes/common.inc, line 663

<?php
function drupal_goto($path = '', array $options = array(), $http_response_code = 302) {
  // A destination in $_GET always overrides the function arguments.
  // We do not allow absolute URLs to be passed via $_GET, as this can be an attack vector.
  if (isset($_GET['destination']) && !url_is_external($_GET['destination'])) {
    $destination = drupal_parse_url($_GET['destination']);
    $path = $destination['path'];
    $options['query'] = $destination['query'];
    $options['fragment'] = $destination['fragment'];
  }

  drupal_alter('drupal_goto', $path, $options, $http_response_code);

  // The 'Location' HTTP header must be absolute.
  $options['absolute'] = TRUE;

  $url = url($path, $options);

  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.
  drupal_exit($url);
}
?>