PHP include ‘header.php’;

Written by: Rick Lamers Posted on: July 21, 2010

Introduction

An HTML file is built with html (<html></html>) header (<header></header>) and body (<body></body) tags.

 

If your making a website, its very likely that the header of each page is the same.
That's the Title-tag and the included .css files or .js files. When you make multiple pages, it's nice to create a reference to a single header file that contains the header data for each page. Also the footer will be the same on most pages. So you can create a footer file which contains the footer for each page,and then reference that footer file on each page.

 

Another advantage of using a shared header and footer section is that one change in the header will be implemented on each page with changing just one file.

 

Example

Here is an example structure of an index.php for let's say the home-page:

 

<?php include 'header.php'; ?>

 

<div id="content">

Here's the actual content for the home-page called index.php

</div>

 

<?php include 'footer.php'; ?>

 

Now if you were to change, for example: the version of the plug in included in the header. And you would then change that in the header file, it will now be changed on the whole site.

 

I hope you understand how the include function works, and make sure to leave your implementation idea's/suggestion below!

 

Till next time, this is Code-Spot.net

About the author:

Name: Rick Lamers
Description: I'm a dutch webdeveloper. I work as a freelancer and I am available for work requests at Reedeesign. My hobby is writing articles on webrelated topics for Code-Spot.net.