The header.php file is where i’m handling the initial HTML code generation. This is where the logic for printing a standard header is contained. We’re using global variables that we obtained from config.php when it was called.

// bunch of global stuff here.
global $db; // so we can call db
global $http_host; // shortcut for $_SERVER[’HTTP_HOST’]
global $stylesheet; // Cascading Stylesheet this page is going to use
global $change_title; // Page’s title
global $category; // Category site belongs to
global $preamble; // Small site description, coming from the DB
global $meta_keywords; // meta keywords
global $meta_description; // meta description

Below is where we set up some important HTML related material. I’m using all those newlines to help keep the HTML output human readable for debugging purposes. Granted, one could argue that they make the PHP code ugly, and they would probably be correct, but I always seem to run into that one HTML tag that is being opened, and never closed, or vice versa, so I like to make the output in somewhat of a tree.

$metas_and_title = ”;
$metas_and_title .= ‘<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”> ‘;
$metas_and_title .= “\n<html>\n”;

// below is our meta tags that we got from the db earlier in config.php
$metas_and_title .= “<meta name=\”keywords\” content=\”$meta_keywords\”>\n”;
$metas_and_title .= “<meta name=\”keywords\” content=\”$meta_description\”>\n”;

// our title line
$metas_and_title .= ‘<title>’.$change_title.’</title></head>’ . “\n”;

Using a Here Document below. Probably an old perl habit I developed, not sure if it’s the most efficient way of printing all this, but I feel that it’s easy to read, and should be easy to maintain.

$header = <<<HTML_HEADER
$metas_and_title
$body_tag

<div id=”container”>
<div id=”intro”>

<div id=”pageHeader”>
<h1><span>main_heading</span></h1>
</div>
<div id=”preamble”>
<h2>$preamble</h2>
</div>
</div>
HTML_HEADER;

Then finally after we create out header in the Here Document, we still need to print it below.

print $header;