PHP Include

This tutorial explains how to include pages with PHP that makes it easier to change pages and layout without having to edit all pages.

First you need to be sure that your host supports PHP, otherwise this tutorial is no use for you. Only a few free hosts support PHP. Contact your host for more information.

1) Make a layout in HTML and when you're done save it as a .php file (for this tutorial let's call it index.php.

2) Make a page with the content you want to include and save it. You can save it as a .txt file, but if you use php codes in the .txt file other people can see it. So it's better to save it as a .php file.

3) In the layout file place this code on the place you want the content to appear.

$p = $_GET['p'];
if ($p) { if (file_exists("$p.php")) { include("$p.php"); } else {   echo "404 Error - Page Not Found"; } } else {
include("page.php"); } ?>

You can change the 'p' into whatever you like, but be sure to change all 'p', otherwise the code won't work. Change page.php into your opening page file, like news/news.php for Fusion News.

4) Go to your browser and type: staff stands for the name the content file has (staff.php) and 'p' is the variable. When you called your layout file index.php you can remove the index.php from the url, so it will looks like this:

The Easy Way

There also a much easier way to include just one php file. The code is:

<? include("page.php"); ?>

Just change page.php to the location where the file is stored that you want to include.

This ends the PHP include tutorial, if you have questions or need help with the code, you can send me a mail using the contact form.