I’m trying to call my websites header which resides in the root directory to other files in other folders.
Root directory
header.php
root/folder/needsheader.php
I cant succesfully get my needsheader.php file to display the header that resides in the root directory. Is there anyway to do it other than using the absolute file name.
include "http://www.website.com/folder/header.php";
The problem is that you’re including a webpage, being requested as such.
You need to include the file directly:
include "folder/header.php";
// or, if you're working in - say - 'folder2' (which resides next to 'folder'):
include "../folder/header.php"
Or you could use the absolute path to the file:
include "/var/www/folder/header.php";
Note that this last version will be problematic if you ever change the folder layout of your website or move to a different host, as you may have to change all your include statements.
You can also use a combination of dirname() and FILE (or DIR depending on your php version) to create an absolute path based on the current file if you prefer that
Thanks Rguy. I’ve been racking my brain over how to do this simple thing. Now I only have edit 160 pages with that code for the footer and header. Thanks. i might get to see sun light today.