index.php 仅在第一次调用时不显示页眉或页脚
index.php doesn't show header or footer only on first call
奇怪的问题:在我的测试主页 http://risklantern.eu/index.php 的第一次调用中,它既不显示页眉也不显示页脚(有时只是不显示页眉)。这是代码:
<body>
<div id="wrapper" class="hfeed">
<?php include ("/titlebar.inc"); ?>
<main id="content">
Main page goes here
</main>
<?php include ("/footer.inc"); ?>
</div>
</body>
如果我改为调用 http://risklantern.eu/blog 然后单击主页,这也会在主目录中调用 index.php,页面看起来应该是这样。
我首先怀疑这是一个目录问题,所以我在不同的地方插入了 getcwd 调用,但它总是在它应该在的目录中。另外,它在我的 XAMPP 本地运行良好,行为仅在在线服务器上。
有人遇到过这样的事情吗?
以斜杠开头的包含路径/
表示根目录,所以在这种情况下我敢打赌那是你的硬盘根目录。尝试将您的真实文档根目录分配给一个变量并将其与 includes 或 requires 一起使用:
$root = $_SERVER['DOCUMENT_ROOT'];
include ($root."/titlebar.inc");
显然,titlebar.inc
必须在您当前的项目根目录中。
奇怪的问题:在我的测试主页 http://risklantern.eu/index.php 的第一次调用中,它既不显示页眉也不显示页脚(有时只是不显示页眉)。这是代码:
<body>
<div id="wrapper" class="hfeed">
<?php include ("/titlebar.inc"); ?>
<main id="content">
Main page goes here
</main>
<?php include ("/footer.inc"); ?>
</div>
</body>
如果我改为调用 http://risklantern.eu/blog 然后单击主页,这也会在主目录中调用 index.php,页面看起来应该是这样。 我首先怀疑这是一个目录问题,所以我在不同的地方插入了 getcwd 调用,但它总是在它应该在的目录中。另外,它在我的 XAMPP 本地运行良好,行为仅在在线服务器上。
有人遇到过这样的事情吗?
以斜杠开头的包含路径/
表示根目录,所以在这种情况下我敢打赌那是你的硬盘根目录。尝试将您的真实文档根目录分配给一个变量并将其与 includes 或 requires 一起使用:
$root = $_SERVER['DOCUMENT_ROOT'];
include ($root."/titlebar.inc");
显然,titlebar.inc
必须在您当前的项目根目录中。