Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6860553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:25:22+00:00 2026-05-27T02:25:22+00:00

I have header.php and footer.php files which I include in all of my pages.

  • 0

I have header.php and footer.php files which I include in all of my pages. A sample page looks like this –

<?php include($_SERVER['DOCUMENT_ROOT'].'/header.php');?>

<div id="content">
...
</div> <!-- content -->

<?php include($_SERVER['DOCUMENT_ROOT'].'/footer.php') ?>

Although this works well on the server, but when I test pages locally [ xampp on Windows 7 ], I get the following error message instead of the header, similarly for the footer –

Warning: include(C:/xampp/htdocs/header.php) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\f\index.php on line 1

Warning: include() [function.include]: Failed opening 'C:/xampp/htdocs/header.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\f\index.php on line 1

This makes testing very tedious as I have to upload to the server for every minor change.

Also, I dug around the WP code, and it uses a get-header() to display the header.php file. I could not completely understand the function. My site does not use WP.

What is the correct way for including header and footer files?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:25:23+00:00Added an answer on May 27, 2026 at 2:25 am

    It seems that $_SERVER['DOCUMENT_ROOT'] is pointing to C:\xampp\htdocs, while your scripts are at C:\xampp\htdocs\f\, check the value of $_SERVER['DOCUMENT_ROOT'] on your local environment.

    edit:

    <?php
    $rootDir = "";
    if(strpos($_SERVER['HTTP_HOST'],'localhost')===FALSE)
    {
      //On Production
      $rootDir = $_SERVER['DOCUMENT_ROOT'];
    }
    else
    {
      //On Dev server
      $rootDir = $_SERVER['DOCUMENT_ROOT'].'/f';
    }
    
    <?php include($rootDir.'/header.php');?>
    
    <div id="content">
    ...
    </div> <!-- content -->
    
    <?php include($rootDir.'/footer.php') ?>
    
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Simply. I have an empty page looking like <?php include(header.php); include(footer.php); ?> That gives
I have thousands of PHP pages which have a header and footer included using
I have my index.php page and just afrer my header i want to include
In my CodeIgniter application have a common header and footer view, which I include
its a little bit hard to understand. in the header.php i have this code:
I have code like <?php header('Content-Type: text/plain; charset=UTF-8'); echo 'Hello Loréane !'; the e
I have created this report using BIRT and phpjavabridge <?php header(Content-type: application/pdf); header(Content-Disposition: inline;
I have a live site that includes different php files depending on what page
I have a bunch of static html files that share same header and footer.
I have a bunch of CSS files that get loaded on every page (header,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.