You are here

function securepages_init in Secure Pages 5

Same name and namespace in other branches
  1. 6.2 securepages.module \securepages_init()
  2. 6 securepages.module \securepages_init()
  3. 7 securepages.module \securepages_init()

Implementation of hook_init()

File

./securepages.module, line 6

Code

function securepages_init() {
  global $base_url;
  $path = isset($_GET['q']) ? $_GET['q'] : '';
  if ($path == 'admin/settings/securepages/test') {
    if (securepages_is_secure()) {
      header('HTTP/1.1 200 OK');
    }
    else {
      header('HTTP/1.1 404 Not Found');
    }
    exit;
  }
  if (!variable_get('securepages_enable', 0) || basename($_SERVER['PHP_SELF']) != 'index.php') {
    return;
  }
  $page_match = securepages_match($path);
  if ($_POST) {

    // If something has been posted to here then ignore the rules.
  }
  elseif ($page_match && !securepages_is_secure()) {
    securepages_goto(TRUE);
  }
  elseif ($page_match === 0 && securepages_is_secure() && variable_get('securepages_switch', FALSE)) {
    securepages_goto(FALSE);
  }

  // Correct the base_url so that everything comes from https.
  if (securepages_is_secure()) {
    $base_url = securepages_baseurl();
  }
}