drupal_add_http_header
- Versions
- 7
drupal_add_http_header($name = NULL, $value = NULL, $append = FALSE)
Set an HTTP response header for the current page.
Note: When sending a Content-Type header, always include a 'charset' type, too. This is necessary to avoid security bugs (e.g. UTF-7 XSS).
Parameters
$name The HTTP header name, or a status code followed by a reason phrase, e.g. "404 Not Found".
$value The HTTP header value; if omitted, the specified header is unset.
$append Whether to append the value to an existing header or to replace it.
Code
includes/bootstrap.inc, line 889
<?php
function drupal_add_http_header($name = NULL, $value = NULL, $append = FALSE) {
// The headers as name/value pairs.
$headers = &drupal_static(__FUNCTION__, array());
if (!isset($name)) {
return $headers;
}
// Save status codes using the special key ":status".
if (preg_match('/^\d{3} /', $name)) {
$value = $name;
$name = $name_lower = ':status';
}
else {
$name_lower = strtolower($name);
}
_drupal_set_preferred_header_name($name);
if (!isset($value)) {
$headers[$name_lower] = FALSE;
}
elseif (isset($headers[$name_lower]) && $append) {
// Multiple headers with identical names may be combined using comma (RFC
// 2616, section 4.2).
$headers[$name_lower] .= ',' . $value;
}
else {
$headers[$name_lower] = $value;
}
drupal_send_headers(array($name => $headers[$name_lower]), TRUE);
}
?>Login or register to post comments 