Including a file is very useful in PHP. Include allows us to add another file into our web page. This particular command can, and probably will, save you hours upon hours of work. Let say you have a webiste that has 7 pages, and every page has the exact same header, navigation, or foot.. In HTML you have to open, edit, save, and re-upload ALL 7 pages. With include, you can add a "header" or "footer" to every page. When it comes time to change something, you only have to edit the one file and it will change on every page. In this included file, you can have more PHP, css, html, javascript... you name it! It literally becomes a part of your page.
Example:
footer.php
<hr />
© Websitename 2011
<a href='contact.php'>Contact Page</a>
Created by <a href='mailto:my_email@example.com'>me</a>
Save the above code as footer.php.
Now save the below code as index.php. Make sure they are in the same directory though, since our index page will only be looking in the directory it's in.
index.php
<html>
<body>
This is my page:
<? include("footer.php"); ?>
</body>
</html>
Now upload both footer.php and index.php, and load index.php in your browser.
Pretty cool huh? Add that little include command into your web sites, and you'll save yourself a lot of time.
It also works with variables instead of a string.
Quick Example:
$footer = "footer.php";
include($footer);
What does the page source look like?
...Like it was always a single file page.
Your task:
Create a new file you want to be included in your page, call it include_this.php
Create index.php, and add regular text or HTML like your normally would, but also use the include command to add include_this.php to your page.