简体   繁体   中英

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'; ?>

你可以这样做:

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

Try

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

And adjust the path as needed, ie ../header .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM