Tutorials

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

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".

<html>
<head>
<title>file include example</title>
</head>
<body>
<?php
include("phpincludefileexample.php");
?>
</body>
</html>

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

<?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.