I love the internet because it connects me to my family and I learn a lot from it.
Ayel

Recent updates

The “I Love” Project

Every year since 2010 I have decided to celebrate my domain's birthday on the 11th October with some kind of project. Last year, it was the 'Love is...' Project and you submitted your definitions of love. This year, you shared what it is that you love.

On the 9th October 2011, this layout was put up with a rotation above the sidebar with chosen submissions. Read more...

Further links

PHP: PHP Includes (Extra Information)

If you are using folders in your website to manage files, upload the header and footer files to your main folder, and on each page, place a slash before the include:

<?php include('../header.php');?>

<?php include('../footer.php');?>

Alternatively, find your absolute path. Paste the following into a .php page, save it as absolutepath.php and upload to your server:

<?php echo $_SERVER['DOCUMENT_ROOT']; ?>

When you view the file, you can see your absolute path, and use that in your include like so:

<?php include('/home/username/public_html/header.php');?>

<?php include('/home/username/public_html/footer.php');?>

Delete absolutepath.php for security reasons.

Other includes

You don’t have to use includes for headers and footers. You can use it for sections in your pages, perhaps for sub navigation or other purposes.

.inc is a common file extension for includes. You can also use .txt. Be careful what you display in these files though, as they are displayed as plain text. Don’t use them to store private data.

<h3><?php include('nav1.inc');?></h3>

You can navigate this section with the links above.

<h1>Recent updates:</h1>
<?php include('updates.txt');?>

Other Statements

We use include, but there are other statements possible. They aren’t necessary to know for PHP includes but I will outline them so you are familiar with them. These do need to be known when writing your own scripts and dealing with them.

<?php require('file.php');?>

require works in a similar way to include. If you have uploaded a file containing an include and the included file doesn’t exist, you will notice a warning, but the rest of the page continues to load.

require produces an error and stops loading the page.

<?php include_once('file.php');?>

This statement is the same as include, but the file will only be included once. If the code has been included it won’t be included again. This is more commonly used in scripts.

<?php require_once('file.php');?>

This statement is the same as require, but the file will only be included (required) once. If the code has been included it won’t be included again. This is more commonly used in scripts.

Related tutorial: PHP: PHP Includes