PHP 8 Beginner Basics · 1 min read

Reuse header with include

Start the PHP 8 learning path »

❮ PHP 8 Home All Tutorials ❯

How do I share a header across pages?

include/require templates.

Example

PHP 8 Example
<?php
require __DIR__ . '/partials/header.php';
?>
<main>Page content</main>
<?php
require __DIR__ . '/partials/footer.php';

Line-by-Line Walkthrough

require fails hard if missing; include warns.

Need more coins?

You do not have enough coins for this action.

Your balance: 0 coins

Share

Reactions

Loading reactions…