The PHP include() statement is useful for creating page templates.
If sections of pages that are common to all pages are placed within include() files then this cuts down on site maintenance.
Any change only needs to made to the include() file without having to change every page on the site.
A Typical Two Column Layout
On the example layout below the only variations between the pages on the site will be the HTML metatags within the head section and the content of the page.
We can create a header section that will include the head section of the page and the logo, a navigation section to hold the page links and a footer section.
These three sections can be created as separate files and included within all pages of the site.
Before including the header we can set the individual metatags for each particular page by using the variables $title, $description and $keywords.
Before including the navigation we can set a variable to signal the page name to the navigation menu. This is to avoid having a page that links to itself.
A Typical Header Section
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><?php echo($title);?></title>
<meta name="<?php echo($description);?>">
<meta name="keywords" content="<?php echo($keywords);?>">
</head>
<body>
<img src="images/logo.gif" width="242" height="48" alt="logo">
In the header above we could alter the logo across the whole site with only one change to the included file.