martin2k

PHP - Creating Headers and Footers for your Site

HomeForumTutorials Tags:
 
 

Contents

Introduction

The Header

The Footer

PHP Code

Introduction

This tutorial will show you how to add a header and footer to all the pages of your site using PHP (PHP: Hypertext Preprocessor).  Your web host must support PHP for this to work.

Instead of recreating the same header and footer on every page on your site, you will have only one set to maintain, which are held in their own files.  They will be linked to your site using two simple lines of PHP code.

The code that is contained in the header and footer files should only include code that would appear between the <body>/</body> tags.  This is because they will make up part of other pages in your site within their BODY tags.

If you create the files using an editor such as Microsoft FrontPage, you will need to delete the default code that is generated e.g.:

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>

<body>

</body>

</html>

The Header

The best thing to put in the header section is the site navigation e.g. buttons or a dropdown box.  You could also include your site's logo, any scripts that are used by your site or HTML code that generates ads.

The Footer

The footer usually contains the name of the person or organisation responsible for the site.  You could also include a link to a contact page (remember never to put your e-mail address on your site), a hit counter or more code for ads.

PHP Code

The following code shows what PHP code to include and where to put it once you have created the files:

<html>

<head>
<title>Title</title>
</head>

<body>
<?php include "header.htm" ?>

Page content

<?php include "footer.htm" ?>
</body>

</html>

You will need to include this code in every page that you want your header and footer to appear in.


blog comments powered by Disqus
© Martin Allen 1999 - 2006.  Last updated Friday 22 December 2006 10:05:26 PM -0000.