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 8292843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:37:02+00:00 2026-06-08T13:37:02+00:00

I’d like to have the same header and footer on every page only with

  • 0

I’d like to have the same header and footer on every page only with different contents using PHP. What is the best approach to do this?

I know of these two popular ones, but don’t know which of them (or maybe some others) to choose:

1. Include header and footer on every page

Into every page like contact.php, about.php, etc. you have to include header on top of the page and footer on the bottom. The content then goes between the too. For example contact.php would look like this:

<?php include("header.php"); ?>
Lorem ipsum dolor sit amet...
<?php include("footer.php"); ?>

When you want to do request, you just type example.com/contact.php

2. index.php?page=xyz

In pages like contact.php, about.php, etc. you store only the actual content. Then you have index.php with some parameter (e.g. page) by which you specify the content to be included. For example the contact.php file would look like this:

Lorem ipsum dolor sit amet...

And the index.php file like this (this is simplified version):

<html>
    <head>
        <title>Lorem ipsum</title>
    </head>
    <body>
        <?php include(some_parser_function($_GET["page"].".php")); ?>
    </body>
</html>

Now when you do request for index.php?page=contact it will show you index.php and between the opening and closing body tags the content from contact.php.

The first approach seems to me a bit unpractical, because you have to write the include functions into every page. In the second approach, if you want to have nice URLs like example.com/contact.php or just example.com/contact, you need to do apache mod_rewriting…

Which one of those (and others) approaches is better / more popular and why?

Thanks.

  • 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-06-08T13:37:04+00:00Added an answer on June 8, 2026 at 1:37 pm

    Option 2 is much better for templating. You can also use Rewrite to make this appear without have ?page=pagename at the end of the url. Also depending on how many pages you have on your site it is kind of a pain to have to do the two includes on every single file.

    However if I were you I would look into using ob_start() ob_get_contents() and ob_flush(). Then you can actually run all the code on the included file before you start outputting html.

    Here is an example:

    ob_start();
    include("{$page_name}.php");
    $page_contents = ob_get_contents();
    ob_end_clean();
    
    ob_start();
    include("templates/standard.php");
    $full_html = ob_get_contents();
    ob_end_clean();
    
    echo $full_html;
    

    This way you can easily create multiple templates to be used at any point. A template file would look like this:

    <html>
        <head>
            <title>Lorem ipsum</title>
        </head>
        <body>
            <?php echo $page_contents; ?>
        </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to count the length of a string with PHP. The string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have two tables with like below codes: Table: Accounts id | username |
I have thousands of HTML files to process using Groovy/Java and I need to
I have some data like this: 1 2 3 4 5 9 2 6
I'm making a simple page using Google Maps API 3. My first. One marker

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.