Jump to content

Help with Includes


phpforsilk

Recommended Posts

Hi there, I have coded a PHP site with mostly HTML so I can utilize include statements for the header and footer and side menus.

 

My issue is this:  I put all of the include files in a folder called includes.  Then some of my files are at the root level and some are one directory lower.  All of the files in different directories work fine with the include statement <?php include('../includes/header.php');?> because the header file is set up to access the various levels of the site "above" the include folder, so for example the header file grabs an image using ../images/whateverpath.

 

When I try to include the header file in index.php (include(includes/header.php)  it doesn't work because the header file is using paths inside the includes folder, if I strip away the ../ from inside the header file, then the index.php file works but then none of the other files in other directories work. 

 

It seems that I would need 2 header files for my site to work, but this isn't very efficient.  How do I make the include files work on all levels of the site regardless of where they reside?

 

If anyone can help me I would be forever grateful as I am very frustrated.

 

Thanks,

 

Link to comment
https://forums.phpfreaks.com/topic/175394-help-with-includes/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.