Skip to content
Discussion options

You must be logged in to vote

The most common approach is to put your shared components into separate files and include them wherever you need them.

For example, you can create an includes folder:

project/
│
├── index.php
├── about.php
├── contact.php
│
└── includes/
    ├── header.php
    ├── navbar.php
    └── footer.php

Then, on each page, simply include those files:

<?php require 'includes/header.php'; ?>
<?php require 'includes/navbar.php'; ?>

<h1>Home Page</h1>
<p>Your page content goes here.</p>

<?php require 'includes/footer.php'; ?>

I usually prefer require for files like the header and footer because they're essential. If one of those files is missing, PHP stops the script immediately, which makes the iss…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@spider-2002
Comment options

Answer selected by spider-2002
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants