PHP HelpPHP Help

Online Community that helps beginners learn PHP,
and webmasters solve PHP coding problems

since 1999

Making the most of Site-wide Headers and Footers

Site-Wide Headers and Footers

One of the most powerful features of PHP is its ability to reduce the amount of site maintenance you need to do. By setting up a consistent site template, you can reduce the effort needed to create new pages, and you can also make it much easier to change the design of your entire site. This tutorial takes you through a simple example of how to set up and access a site template.

Tip:  It may not be immediately clear that any pages including headers and footers must be "made dynamic" by converting them from static HTML pages to PHP pages. For example, to make your homepage capable of including headers and footers rename it with the .php extension (or whatever extension you are using to denote PHP scripts on your server) and add the PHP code for the includes. Included files are not required to have the .php extension, but can be called .html or even a made up type like .inc or .inf. Whatever they are called, included files will be executed.

The first thing you need to do is design your HTML header and footer. This is all of the information that is presented the same way in all of your pages. The header typically includes the HEAD section of your site, perhaps a button bar and site advertising, and the page heading. The footer typically includes a copyright notice and contact information for your site. Here are some examples:


<TITLE>>My Cool Site</TITLE>
<H1>The Coolest Site Ever</H1>


<A HREF="http://www.coolsite.loc/legal.php">Copyright</A> 1999 By Me<BR>
Written by: <I>The Author</I><BR>
Questions? Write to <B>me@coolsite.loc</B><BR>


require ("/path/to/includes/header1.php");
<P>This is a the text of your page. Make it as fancy as you want!</P>
require ("/path/to/includes/footer1.php");
Pages:  1   2   3Next:  Dynamic Headers and Footers »

Copyright © 2018