You are here

function mobile_tools_goto in Mobile Tools 5

Same name and namespace in other branches
  1. 6.3 mobile_tools.module \mobile_tools_goto()
  2. 6 mobile_tools.module \mobile_tools_goto()
  3. 6.2 mobile_tools.module \mobile_tools_goto()
1 call to mobile_tools_goto()
mobile_tools_detection_boot in ./mobile_tools.module
Being called in the hook_init() implementation This function is in charge of device detection, redirection or displaying a notification

File

./mobile_tools.module, line 1080
Mobile Tools provides a range of functionality assisting in creating a mobile drupal site . this functionality contains:

Code

function mobile_tools_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;
}