An Introduction to PHP

Server-side includes

A server side include is a file that is included within the current document on the server. This can save the developer a considerable amout of time. If all of the pages on your site have a similar header, you can include a single file containing the header into your pages. When the header needs updating, you only update the one page, which is included in all of the pages that use the header. As many include files may be used as required.

In PHP, server side includes are achieved using the require statement. The following example includes a banner that contains a logo and set of links for the pages.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
            "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Server Side Include</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<?php require("banner.html"); ?>
<p>
This page contains a banner that may be incuded in any
of the PHP files used on this site.
</p>
</body>
</html>

You might also like...

Comments

About the author

Gez Lemon United Kingdom

I'm available for contract work. Please visit Juicify for details.

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“It works on my machine.” - Anonymous