Create simple php code that adds header and footer using include statement.
Header and footer are the two most important part for every web application because dynamic content serving websites contain more pages than a normal website and on most of the websites the header and the footer section are same for every page so with the use of include statement website developer can easily add header, footer with the use of single line of code so there is no need to create or copy paste large amount of header footer code. So here is the complete step by step tutorial for How to include header and footer in PHP page example.
What is header : Header part is the website’s upper top level portion which is hold its title, tag line, primary horizontal menus, website logo.
What is footer : Footer section is website’s lower bottom section which contain its copyright information, some times top level horizontal menus.
What we are doing in this tutorial : We are creating three files header.php, footer.php, mainPage.php . Now we are adding header.php and footer.php into mainPage.php using include statement.
How to include header and footer in PHP page example.
Code for header.php file.
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Header.PHP file</title> </head> <body> <h2>This Code comes from Header.php file.</h2>
Code for mainPage.php file.
<?php include 'header.php' ?> <h2> Main Body part </h2> <?php include 'footer.php' ?>
Code for footer.php file.
<h2>This Code comes from Footer.php file.</h2> </body> </html>