对于我正在进行的项目,我想用一个中心PHP文件远程更改导航栏。该文件应该控制我网站上的更多页面。当这个PHP文件和HTML页面在同一个文件夹中时,它可以很好地使用require_once
和文件名。尽管它不适用于路径——在这种情况下,它只是我的服务器的根。我该如何解决这个问题?
这就是我认为require_once
如何使用路径:
<?php
require_once 'http://root.com/template_default.php';
?>
(我使用http://root.com/
作为根路径的占位符。)
我希望有人能帮我。提前感谢:)
我不确定这是不是你的意思?
<?php
set_include_path( $_SERVER['DOCUMENT_ROOT']."/" );
?>
<html>
<head>
<title>include/require local file from document root</title>
</head>
<body>
<nav>
<?php
include 'template_default.php';
?>
</nav>
<h1>hello world</h1>
</body>
</html>