Contributions API

path_redirect_goto

Definition

path_redirect_goto($path = '', $query = NULL, $fragment = NULL, $http_response_code = 302)
contributions/path_redirect/path_redirect.module, line 194

Description

This is a copy of drupal_goto() redesigned for use during the bootstrap

Code

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

  $url = $path;

  // Make the given path or URL absolute
  if (!preg_match('/^[a-z]+:\/\//', $url)) {
    global $base_url;
    $url = $base_url .'/'. $url;
  }

  $url .= (empty($query)    ? '' : '?'. $query);
  $url .= (empty($fragment) ? '' : '#'. $fragment);

  // 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.
  bootstrap_invoke_all('exit');

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