简体   繁体   中英

index.php doesn't show header or footer only on first call

strange problem: on the first call of my test homepage http://risklantern.eu/index.php , it doesn't show either header or footer (and sometimes just not the header). Here's the code:

  <body>
    <div id="wrapper" class="hfeed">
       <?php include ("/titlebar.inc"); ?>
       <main id="content">
            Main page goes here
       </main>
       <?php include ("/footer.inc"); ?>
    </div>
 </body>

If I instead call http://risklantern.eu/blog and then click on home, which also calls index.php in the main directory, the page looks as it should. I first suspected it was a directory problem, so I inserted getcwd call at various points, but it is always at the directory where it should be. Plus, it runs fine on my XAMPP locally, the behavior is only on the online server.

Anybody encounter something like this before?

The include path, beginning with slash / indicates the root, so in this case I bet that is your hard disk root. Try to assign your real document root to a variable and use it with includes or requires:

$root = $_SERVER['DOCUMENT_ROOT'];
include ($root."/titlebar.inc");

Obviously, titlebar.inc must be in your current project root.

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