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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:30:09+00:00 2026-05-20T03:30:09+00:00

OK, so for the first time I am building a full website and working

  • 0

OK, so for the first time I am building a full website and working with php. Now I encounter a problem:

Let’ss say my site is simply has a header with a menu and a area with content. Of course, I would like to have a header.php and several content files like content1.php content2.php and content3.php for example. This way you only have to change the menu in 1 file as you would understand.

How then is it best to build the site:

A. put something like this in every content file:

  <?php include 'header.php'; ?>

  here the content of the content page 1

B. make an index file with something like:

   <?php include 'header.php'; ?>

   <?php include 'content1.php'; ?>

how then is it done that when in the menu the link to content2.php is clicked the header is still on that page too?

C. something else? Maybe a good tutorial on how to make these kind of pages?

  • 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-20T03:30:10+00:00Added an answer on May 20, 2026 at 3:30 am

    If you’re looking to maximize the benefit of reusing code/elements, then you’re on the right track with your second option:

    B. make an index file with something like:

    <?php include 'header.php'; ?>
    <?php include 'content1.php'; ?>
    

    how then is it done that when in the menu the link to content2.php is clicked the header is still on that page too?

    Here’s how (a simplistic example):

    Route all of the similar requests (content1,2,3) through your index.php script using the query string – mod_rewrite can make this pretty. Then serve the main content section based on the request.

    For example a link:

    <a href='index.php?page=content1'>Content 1</a>
    

    And detecting the content to serve:

    <php
        $pages['content1'] = 'content1.php';
        $pages['content2'] = 'content2.php';
    
        $pages['default'] = $pages['content1']; //set default content
    
        $page = 'default';
        if(isset($pages[$_GET['page']]){
            $page = $pages[$_GET['page']]; //make sure the filename is clean
        }
    
    ?>
    <?php include 'header.php'; //header here?>
    <?php include $page; //correct content here?>
    

    Not only is there a single place to change your header, but now there’s a single place to change your entire layout.

    Of course this is just a simplistic example, there are many PHP frameworks that do all this for you (using MVC).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first time working on php code. I've put some printf code
I am building a firefox addon for the first time. When I try to
This is my first time posting -- I found similar issues but not anything
The very first time you start a push app, the user gets asked if
long time reader, first time asker... I am making a music app which uses
I'd like to present a first-time user with a welcome message that appears until
I'm building an app that needs to be able to extend facebook graph data.
I'm receiving the error 'currentUpdateMethod' undeclared (first use in this function). The variable this
being a Java/Linux advocate, and having programmed my first Android app a while ago,
How to achieve an android:background change effect on multiple Views at the same time,

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.