Using PHP header templates with different titles on each page
It's common to include a file called header.php to create a common header throughout a website.
However, it's also important to change the description and title of each page to match the content that's on them. This is particularly important when your users will find you using google. A good description will appear right there on the result page and help people figure out whether your page is relevant to their needs.
Here's how you do it.
First, modify your regular file, header.php, to take two variables- \$title, and \$description.
<?php
header("Content-type: text/html;charset=iso-8859-1");
if(!isset($description))
{
$description = 'Default description for your site';
}
if(!isset($title))
{
$title = 'Default page title for your site';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" \
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> <? echo $title ?> </title>
<meta name="description" content="<? echo $description ?>">
... etc ...
By the way, if you're looking for a good book on php, check out
this book
Now, for each page, your include works like this;
$title = 'Write your title here!';
$description = 'Write your description here!';
include $_SERVER['DOCUMENT_ROOT']."/header.php";