Skip to Content

PHP

drupal_goto()

drupal_goto($path = '', $query = NULL, $fragment = NULL, 
$http_response_code = 302)

This simple function initiates an immediate redirect of the user to the URL indicated. The function contains additional parameters to handle complex URL building and supports RFC 2616 by registering an HTTP code for the redirect.

The parameters are parsed by this code fragment:

$url = url($path, array('query' => $query, 'fragment' => $fragment, 'absolute' => 
TRUE));

The array is relatively straight forward with the [0] element as the actual address, and the query(if any) loaded into an associative part of the array and the fragments(if any) also loaded into an associative part of the array.

The PHP function 'header()' does the heavy lifting in the function by setting the destination and giving the response code to the users browser:
header('Location: '. $url, TRUE, $http_response_code);

header()

void header ( string $string [, bool $replace= true [, int $http_response_code ]] )

$string = "The URL to be inserted into the header"
$replace = "Boolean to replace existing header or add to existing header"
$http_response_code = "As defined in RFC 2615"

PHP "The Rambling Guide"

Various code tricks, techniques, snippets, puzzles, bugs, inconsistencies, patterns and other such stuff.

Syndicate content