Create the header and footer files:
Create a file called "header.php" and enter the html code that you'd like at the top of each page as follows:
Create a file called "footer.php" and enter the html code that you'd like at the bottom of each page as follows:
Now we will create a web page that uses these headers and footers.
Create a file called "page.php" and enter the following html code:
We set the title for the page using (1)
We then include the header page using (2)
And we include the footer page using (3)The final page should look like this:
Files included in this way act as if their text was inserted into the main document right at the include() call. PHP then continues to process the inserted file, allowing the inserted file to access all previously defined variables and functions (so $title in header.php was replaced with the value set in page.php: "Welcome"). This can have unintended consequences if a file is included more than once. To learn how to correctly include files containing functions and classes, see PHP Include Files.
Return to PHP.