Learn web design and programming with our free video and text tutorials.

Web Designer? Design and market your own professional website with easy-to-use tools.

PHP File include() Tutorial

PHP allows you to use server side includes (SSI) to include a file as part of your document(s) while the included file(s) are stored on the server. One common use of SSI is store the data such as header or footer information which is repeated many times on the website.

The include and require statements function the same, except that any errors that are found in a require statement are considered fatal, meaning that the application terminates with an error.

Create a php document like the one below and name it "phpincludefile.php".

<title>file include example</title>

Next, create a php document like the one below and name it "phpincludefileexample.php".

echo "This in an include file.";

The phpincludefile.php file will should display the contents that are in the phpincludefileexample.php file. Any changes that are made to the phpincludefileexample.php file will also appear on any document or file containing the <?php include("phpincludefileexample.php"); ?> script.