Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Include a file in a PHP page

You can easily include the same piece of content on multiple pages in your site by using include files, files that are included dynamically in a web page when the page is rendered in the browser.

Include files can make sites easier to manage. For example, you can create a piece of content such as a page banner, site information block, or menu that you want to include on multiple pages in your site. When you want to change the content, you can make the change in a single file, and the change will be reflected on every page in which the include file appears.

A PHP include statement is a code block that pulls content from an external file into a web page. The following is an example of a PHP include statement:

<?php include('pageBanner.php'); ?>

There are two basic PHP include functions: include() and require(). Both behave in the same way, but return different errors. An include() function, if not parsed correctly, will continue processing the rest of the page and display a warning in the page where the included file should appear. If a require() function refers to a missing file, the function will stop processing the page and display an error page in the browser. For more information about include() and require(), see PHP Include Files on the W3 Schools site.

The include_once() and require_once() functions specify that an include file be used only once in a page. If two include() functions refer to the same include file, only the first include() function will display in the browser. For more information, see include_ and require_once on the PHP.NET site.

Microsoft Expression Web supports using four different file types as include files: HTML, INC, PHP, and TXT files. In addition, you can also create nested include files. For example, you can create an include file which contains a reference to another include file.

  1. On the Insert menu, click PHP, and then click one of the following include() functions:

    • Include   Includes the file each time it is referenced in the page.

    • Include_once   Includes the file the first time it is referenced in the page.

    • Require   Requires that the file be processed before the page is returned, and includes the file each time it is referenced in the page.

    • Require_once   Requires that the file be processed before the page is returned, and includes the file the first time it is referenced in the page.

  2. In the Select a PHP page dialog box, select the file that you want to include, and then click Open.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.