drupal_goto

  1. drupal
    1. drupal6
    2. drupal7
Versionen
drupal6 – drupal7 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 destination 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/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.

Übergabeparameter

$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:

  • 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()

▾ 28 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.
batch_process in includes/form.inc
Processes the batch.
comment_multiple_delete_confirm in modules/comment/comment.admin.inc
List the selected comments and verify that the admin really 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:
drupal_redirect_form in includes/form.inc
Redirect the user to a URL after a form has been processed.
filter_admin_delete in modules/filter/filter.admin.inc
Menu callback; confirm deletion of a format.
locale_languages_delete_form in includes/locale.inc
User interface for the language deletion confirmation screen.
locale_translate_edit_form in includes/locale.inc
User interface for string editing.
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.
search_admin_settings_validate in modules/search/search.admin.inc
Validate callback.
search_view in modules/search/search.pages.inc
Menu callback; presents the search form and/or search results.
system_actions_configure in modules/system/system.module
Menu callback. Create the form for configuration of a single action.
system_actions_remove_orphans in modules/system/system.module
Remove actions that are in the database but not supported by any enabled module.
system_admin_compact_page in modules/system/system.admin.inc
Menu callback; Sets whether the admin menu is in compact mode or not.
system_goto_action in modules/system/system.module
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.
trigger_assign in modules/trigger/trigger.admin.inc
Build the form that allows users to assign actions to hooks.
trigger_unassign in modules/trigger/trigger.admin.inc
Confirm removal of an assigned action.
trigger_unassign_submit in modules/trigger/trigger.admin.inc
update_manual_status in modules/update/update.fetch.inc
Callback to manually check the update status without cron.
user_admin_role in modules/user/user.admin.inc
Menu callback: administer roles.
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_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 in modules/user/user.module
Form builder; The user registration form.
_batch_finished in includes/batch.inc
End the batch processing: Call the 'finished' callbacks to allow custom handling of results, and resolve page redirection.

Code

includes/common.inc, line 312

<?php
function drupal_goto($path = '', $query = NULL, $fragment = NULL, $http_response_code = 302) {

  $destination = FALSE;
  if (isset($_REQUEST['destination'])) {
    $destination = $_REQUEST['destination'];
  }
  else if (isset($_REQUEST['edit']['destination'])) {
    $destination = $_REQUEST['edit']['destination'];
  }

  if ($destination) {
    // Do not redirect to an absolute URL originating from user input.
    $colonpos = strpos($destination, ':');
    $absolute = ($colonpos !== FALSE && !preg_match('![/?#]!', substr($destination, 0, $colonpos)));
    if (!$absolute) {
      extract(parse_url(urldecode($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();
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen