You are here

function hsts_init in HTTP Strict Transport Security 6

Same name and namespace in other branches
  1. 7 hsts.module \hsts_init()

Implements hook_init().

Sets the header in all requests to include the HSTS max-age value

File

./hsts.module, line 14
Main module file for hsts.

Code

function hsts_init() {

  // Set the header to include the HSTS data
  if (variable_get('hsts_enabled', FALSE) == 1) {

    // Add the max age header
    $hsts_header = 'Strict-Transport-Security: max-age=' . check_plain(variable_get('hsts_max_age', 500));
    if (variable_get('hsts_subdomains', FALSE)) {

      // Include subdomains
      $hsts .= ';includeSubDomains';
    }

    // Add the header
    drupal_set_header($hsts_header);
  }
}