Include Header navigation and Footer in PHP

Include Header navigation and Footer in PHP

Today, We want to share with you Include Header navigation and Footer in PHP.
In this post we will show you Creating global php header and footer files for beginners, hear for How to Create a site-wide Header, Sidebar, and Footer in PHP we will give you demo and example for implement.
In this post, we will learn about How to Include HTML in Many Documents Using PHP with an example.

What is header?

The Header file part is the websites portion of the upper top level portion which is all hold its title and more.., Like as a tag line data, primary horizontal menus items, website logo.?

What is footer?

The Footer file section is websites portion of the lower bottom section part which contain it is a copyright information and footer menu, some times every top level horizontal navigation menus.

Create simple Example of php code that adds new header part and footer part using include statement in PHP code.

Process of The Include Header and Footer

  • 1st : How to use PHP includes
  • 2nd : Create your include files
    • header.php
    • menu.php
    • footer.php
    • index.php
  • simple Convert your page to PHP
  • Now Last step Add the all includes to your every pages call

Example of Include header and footer in PHP script


$PageTitle="New Page Title -";
echo '<a href="index.php" alt="" title="">Home Page</a><br>';


echo '<a href="overview.php" alt="Overview" title="Overview">Overview</a> -
<a href="comparison.php" alt="Comparison" title="Comparison">Comparison</a> -
<a href="scorecard.php" alt="Scorecard" title="Scorecard">Scorecard</a> -
<a href="linechart.php" alt="Line Chart" title="Line Chart">Line Chart</a> -
<a href="about.php" alt="About" title="About">About</a>';


echo "<p>@Copyright © 2005-" . date("Y") . "</p>";


    <title><?php isset($PageTitle) ? $PageTitle : ""?></title>
<?php include 'header.php';?>
<?php include 'menu.php';?>
<h1>Welcome to Thanks a lot.</h1>
<p>Thanks a lot.</p>
<?php include 'footer.php';?>

There are List of Technical Considerations

  • include()
  • require()
  • include_once()
  • require_once()

Simple Use one of the following List:

//this way is true.List of way include header
require 'header.php';
require_once 'menu.php';
include 'footer.php';
include_once 'sidebar.php';
Extra Note:

/ * The following lines are incorrect, but work:
include_once('navigation.php'); */

Using jquery to Include header/footer


PHP include header/footer

Example 1 : header/footer

//include header
<?php include("header.php"); ?>
<div id="page-content">
somecode display...........
//include footer
<?php include("footer.php"); ?>

Example 2 : header/foote

<!DOCTYPE html>
<?php include("header.php"); ?>
//include header
<div id="page-content">
<h2>This some Code comes from Header.php file.
somecode....display Body part
//include footer
<?php include("footer.php"); ?>

include header and footer in PHP page example

File of the Code for header.php file.

<!doctype html>
<meta charset="utf-8">
<title>Include header and footer in PHP page example.</title>
<h2>This some Code comes from Header.php file.</h2>

Code for footer.php file.

 <h2>This Simple file Code comes from Footer.php file.</h2>

Include Code for index.php file.

<?php include 'header.php' ?>
<h2> Call The Header and Footer file and display Main Body part </h2>
<?php include 'footer.php' ?>

create header file and Footer file automatically


<?php require 'headercommon.php?id=head';
echo "My Body Part here : welcome to dear guest.";
require 'headercommon.php?id=foot' ?>


$id_val = $_GET['id'];

if ($id_val == 'head') {
    echo "Header part Display";
} elseif($id_val == 'foot')
    echo "footer Part Dispaly";
} else {
    echo "Oops, error generated no id_val specified!";


Related FAQ

Here are some more FAQ related to this Article:

  1.   react open new tab Example with Tutorial
  2.   Print last query in laravel eloquent - Examples
  3.   PHP file_get_contents URL Examples
  4.   Setup Laravel 6 Login Authentication
  5.   jQuery AJAX Submit form serialize PHP MySQLi
  6.   PHP Highlight search matching text Results with Mysql
  7.   Vue.Js Date & Time Function with Example
  8.   Create Different CSS Geometric Shapes with Example
  9.   How to convert a String to Char Array in Java?
  10.   ng-mousedown Event using Angular Example