Using PHP Includes

Using PHP Includes
Difficulty: Easy
Description: Including other files in your scripts.
Author: M@ster; Date Added: 2008-12-30; Views: 8777
To use includes in your pages the files must have the extension .php in order for it to work. (unless you specify for other file extensions to be parsed in your server config) What this is used for is to include other pages/files into another file. This is commonly used to include a header file and a footer file.

Here is the code that includes the page:
include "header.php";

If your file is not in the same folder as your other page just change header.php to where ever the file is located.

require does basically the same thing as include the only difference is that require stops executing the page if theres an error and include does not stop.

An example of require would look like:
require "header.php";

If the file does not exist, it will generate and error.

Here is an example:

File named: include.php
Welcome to my site.

Please enjoy it here!

Second page.

include "include.php";

The output in the index.php file would be:

Welcome to my site.

Please enjoy it here!

The same results would come when using require.

Hope this tutorial helped!