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

header.php

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

menu.php

<?php
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>';
?>

footer.php

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

index.php

<html>
<head>
    <title><?php isset($PageTitle) ? $PageTitle : "w2way.com"?></title>
</head>
<body>
<?php include 'header.php';?>
<?php include 'menu.php';?>
<h1>Welcome to Pakainfo.com. Thanks a lot.</h1>
<p>Regards</p>
<p>Thanks a lot.</p>
<?php include 'footer.php';?>
</body>
</html>

There are List of Technical Considerations

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

Simple Use one of the following List:

<?php
//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:
require('header.php');
require_once('footer.php');
include('menu.php');
include_once('navigation.php'); */
?>

Using jquery to Include header/footer

$('#headerfile').load('libs/header.php')
$('#footerfile').load('libs/footer.php')

PHP include header/footer

Example 1 : header/footer

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

Example 2 : header/foote

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

include header and footer in PHP page example

File of the Code for header.php file.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Include header and footer in PHP page example.</title>
</head>
<body>
<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>
 <p>@copyright2000-20019</p>
</body>
</html>

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

index.php

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

headercommon.php

<?php
$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!";
}
?>

DEVELOPMENT


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