![](/img/trans.png)
[英]header('location:index.php') doesn't work in the first run
[英]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本地運行良好,該行為僅在在線服務器上。
有人遇到過這樣的事情嗎?
包含路徑(以斜杠/
開頭)表示根,因此在這種情況下,我敢打賭這是您的硬盤根。 嘗試將實際文檔的根分配給變量,然后將其與include或require一起使用:
$root = $_SERVER['DOCUMENT_ROOT'];
include ($root."/titlebar.inc");
顯然, titlebar.inc
必須在您當前的項目根目錄中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.