serhio
serhio

Reputation: 28586

Correctly include php header in all pages

I would include a php header (mysite.com/header.php) in all the pages from a site.

How to do it properly?

There are relative links:

<?php include_once 'header.php'; ?>
<?php include_once '../header.php'; ?>

And this didn't help:

<?php include_once '/header.php'; ?>

Upvotes: 0

Views: 1692

Answers (2)

You can do something like this:

include($_SERVER["DOCUMENT_ROOT"] . "/header.php");

Upvotes: 2

Josh K
Josh K

Reputation: 28893

Try

<?php require_once('./header.php'); ?>

And adjust the path as needed, i.e. ../header.

Upvotes: 0

Related Questions