drupal_goto

Хочешь помочь с переводом? Это очень просто и быстро. Лишь зарегистрируйся, и можешь тут же начать переводить.

includes/common.inc, строка 303

Версии
5 – 6
drupal_goto($path = '', $query = NULL, $fragment = NULL, $http_response_code = 302)

Перенаправляет пользователя на другую страницу сайта на Друпале.

Эта функция относится к внутрисайтовой HTTP-переадресации. Функция проверяет, является ли указанный для перехода URL корректно сформированным.

Обычно URL для перехода составляется из входных параметров функции. Однако, вы можете изменить подобный ход событий, установив путь назначения или в массиве $_REQUEST (например, использую в строке запроса URI) или в массиве $_REQUEST['edit'] (например, используя скрытое поле формы). Эти способы используются для переадресации пользователя к нужной странице после заполнения формы. Например, после редактирования сообщения на странице 'admin/content/node' или после авторизации, используя блок 'user login' в боковой панели. Для того, чтобы помочь установить URL для переадресации может быть использована функция drupal_get_destination().

Друпал будет удостоверяться, что сообщения, сформированные функцией drupal_set_message() и другие данные сессии записаны в базу данных прежде чем пользователь будет переадресован.

Эта функция заканчивает запрос; лучше использовать её чем выражение print theme('page') в вашем обратном вызове для меню.

Смотрите также

drupal_get_destination()

Параметры

$path Путь Друпала или полный URL.

$query Компонент строки запроса, если есть.

$fragment Идентификатор фрагмента страницы, куда ведется переадресация (именованный якорь).

$http_response_code Допустимые значиния для существующей команды 'goto' по спецификации RFC 2616, секции 10.3:

  • 301 Move Permanently (рекомендуемое значение для большинства переадресаций)
  • 302 Found (используемое по умолчанию в Друпал и PHP, иногда используется для спама поисковых движков)
  • 303 See Other
  • 304 Not Modified
  • 305 Use Proxy
  • 307 Temporary Redirect (альтернатива '503 Site Down for Maintenance')
Замечание: Есть и другие значения по спецификации RFC 2616, но они редко используются и плохо поддерживаются.

▾ 34 функции вызывают drupal_goto()

aggregator_admin_refresh_feed in modules/aggregator/aggregator.module
Колбэк меню; обновляет фид, затем перенаправляет на страницу обзора фида.
comment_admin_overview_validate in modules/comment/comment.module
We can't execute any 'Update options' if no comments were selected.
comment_multiple_delete_confirm in modules/comment/comment.module
List the selected comments and verify that the admin really wants to delete them.
comment_multiple_delete_confirm_submit in modules/comment/comment.module
Perform the actual comment deletion.
comment_reply in modules/comment/comment.module
This function is responsible for generating a comment reply form. There are several cases that have to be handled, including: replies to comments replies to nodes attempts to reply to nodes that can no longer accept comments respecting access...
contact_admin_delete in modules/contact/contact.module
Коллбэк меню. Страница удаления категорий.
drupal_redirect_form in includes/form.inc
Перенаправляет пользователя на URL после обработки формы.
filter_admin_delete in modules/filter/filter.module
Menu callback; confirm deletion of a format.
legacy_blog_feed in modules/legacy/legacy.module
Menu callback; redirects users to new blog feed paths.
legacy_taxonomy_feed in modules/legacy/legacy.module
Menu callback; redirects users to new taxonomy feed paths.
legacy_taxonomy_page in modules/legacy/legacy.module
Menu callback; redirects users to new taxonomy page paths.
locale_admin_manage_delete_form in modules/locale/locale.module
User interface for the language deletion confirmation screen.
menu_confirm_disable_item_submit in modules/menu/menu.module
node_configure_validate in modules/node/node.module
Form validate callback.
node_page_edit in modules/node/node.module
Menu callback; presents the node editing form, or redirects to delete confirmation.
node_revision_delete in modules/node/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/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_cancel in modules/poll/poll.module
Callback for canceling a vote
poll_vote in modules/poll/poll.module
Callback for processing a vote
search_admin_settings_validate in modules/search/search.module
Validate callback.
search_view in modules/search/search.module
Menu callback; presents the search form and/or search results.
system_admin_compact_page in modules/system/system.module
system_modules_uninstall_submit in modules/system/system.module
Processes the submitted uninstall form.
system_modules_uninstall_validate in modules/system/system.module
Validates the submitted uninstall form.
system_run_cron in modules/system/system.module
Menu callback: run cron manually.
user_admin_role in modules/user/user.module
Menu callback: administer roles.
user_edit in modules/user/user.module
user_login in modules/user/user.module
user_logout in modules/user/user.module
Menu callback; logs the current user out, and redirects to the home page.
user_menu in modules/user/user.module
Реализация hook_menu().
user_pass_reset in modules/user/user.module
Menu callback; process one time login link and redirects to the user page on success.
user_register in modules/user/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.

Код

<?php
function drupal_goto($path = '', $query = NULL, $fragment = NULL, $http_response_code = 302) {
  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);

  // 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 go wrong, so we make sure none
  // of the code below the drupal_goto() call gets executed when we redirect.
  exit();
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

Вход в систему