Reputation: 317
I'm having trouble including a header in my website. The code I'm using is:
<?php include_once('header.php'); ?>
The page that I'm including this PHP code on is a PHP page itself, so surely it should be working?
The page is located inside folders, e.g. "http://mydomain.com/stuff/morestuff/index.php" Whereas on the FTP the header.php is located at "http://mydomain.com/header.php" - is this why it's not including the header file? Because it can't find it?
But when I do:
<?php include_once('http://mydomain.com/header.php'); ?>
There aren't any errors but the page is blank.
How do I fix this? Basically, how do I include a header on my website?
How do I access the "header.php" file that is located at the root of my website directory?
Upvotes: 1
Views: 91
Reputation: 697
I think that PravinS' answer should work. Your way is also correct, but I think that you maight have disabled allow_url_include in php.ini.
Just use /header.php, and leave allow_url_include option disabled for security reasons (unless you need it).
Upvotes: 0
Reputation: 209
Use error_reporting(-1); and ini_set('display_errors', true); in the top of your main file in order to show all errors. There will be a PHP warning with detailed description why file isn't included
Upvotes: 0
Reputation: 23480
You need to navigate two folder up from index script
<?php include_once('../../header.php'); ?>
You can always use ../
to navigate in upper folder.
From documentation
For example, if a filename begins with ../, the parser will look in the parent directory to find the requested file.
Upvotes: 1
Reputation: 2584
include header.php like this
<?php include_once('/header.php'); ?>
Upvotes: 1