Header.php

So basically I make my files include

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

To update the sites fast by just editing the header.php.

However, I have to include this header.php file into every directory and then update the header.php file into every directory where it is in. Is there any way where I can make it so that it just refers to one header.php in a directory? So I dont have to include it in every directory and update it in every directory?

You can have your header.php file in your website root and then reference it with

<?php
include $_SERVER["DOCUMENT_ROOT"] . "/header.php";
?>

Or have it inside of a directory called “includes” in the root and reference it like so:

<?php
include $_SERVER["DOCUMENT_ROOT"] . "/includes/header.php";
?>

Then again, it is all up to you to decide the name of the directory, so feel free to modify the code.

8 Likes

thanks, it works, one more thing is that you should add " ob_start(); " at the top, above the include statement, that way it wont tamper with header redirects.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.