Current course:

PHP "include"


PHPs "include" will take the contents of the included file, and insert it into the current file at the location of the include.

The Code:

<? include('includes/menu.php'); ?>


It's offen used for things like menus, where the menu will stay the same between pages. If we include the menu, instead of "hard-coding" it to every page, when we want to update the menu, we'll only have to change it in the menu file, and each of our sites pages will just include that file.

Another common use for an include, is to create an "header.php" file which contains all of the content that exists on every page of a site. So, we can cut the open HTML tag, the entire HEAD tag and all of it's contents, as well as the open BODY tag, and any of the sites contents (like the menu) that will be on every page, and save it to the "header.php" file.

Then, we can save the close BODY and close HTML tags in an "footer.php" file.

Once that's done, each page will look something like this:
<? include('includes/header.php'); ?>

content of the page goes here.

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