| 5 common.inc | drupal_set_header($header = NULL) |
| 6 common.inc | drupal_set_header($header = NULL) |
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).
File
- includes/
common.inc, line 146 - Common functions that many Drupal modules will need to reference.
Code
<?php
function drupal_set_header($header = NULL) {
// We use an array to guarantee there are no leading or trailing delimiters.
// Otherwise, header('') could get called when serving the page later, which
// ends HTTP headers prematurely on some PHP versions.
static $stored_headers = array();
if (strlen($header)) {
header($header);
$stored_headers[] = $header;
}
return implode("\n", $stored_headers);
}
?> Login or register to post comments
Comments
---
In Drupal 7, the equivalent function is drupal_add_http_header().
Setting no Cache
putting this here so that when I need it again, i will find it i a logical place :P
/* setting up the site to no cache data */function some_module_name_set_page_headers(){
drupal_set_header("CacheControl: no-cache");
drupal_set_header("Pragma: no-cache");
drupal_set_header("Expires: -1");
}
it is Cache-Control not
it is Cache-Control not CacheControl :)
Same thing in the theme layer
Because I live in the theme layer ->
// put this in template.phpfunction theme_name_page_headers(){
drupal_set_html_head('<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">');
drupal_set_html_head('<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">');
}
This is very important: you need to call it from the preprocessing page function:
// also in template.php
function theme_name_preprocess_page(&$vars, $hook) {
theme_name_page_headers();
$vars['head'] = drupal_get_html_head();
?>
In case you come across this
In case you come across this in search like I did the equivalent in D7 is drupal_add_http_header.
http://api.drupal.org/api/drupal/includes--bootstrap.inc/function/drupal...