I wrote a website in HTML but then I wanted the header and navbar portion in one file so I just had to change it once. I changed all the pages to .php and added the php includes. However now I get an error on pages that I've put in folders so I could create cruftless links.
Header file: /test/assets/header.php
Works: /test/index.php
contains <?php include 'assets/header.php'; ?>
Throws Error: /test/company/index.php
contains <?php include '/test/assets/header.php'; ?>
Error:
Warning: include(/test/assets/header.php) [function.include]: failed to open stream: No such file or directory
Warning: include() [function.include]: Failed opening '/test/assets/header.php' for inclusion (include_path='.:/usr/local/lib/php:/usr/local/php5/lib/pear')
I am having an issue linking to the header file that is in a folder in the root folder. I believe it is a simple issue of just not knowing how to input the URL. If I attempt to include the full path to the header.php I get a URL file-access is disabled
error
If you start a path with a
/
then it's an absolute path. Absolute mains to the actual filesystem root directory, not the virtualdocument root
. This is why it fails.Commonly this is what was meant:
It's not a URL; it's a filepath (although you can use full URLs when the server configuration allows it).
I was also facing the same warnings:
I solved them with the following solution:
You have to define your path then use include function as below:
After that, you can use any directory structure.