phpforsilk Posted September 24, 2009 Share Posted September 24, 2009 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, Quote Link to comment https://forums.phpfreaks.com/topic/175394-help-with-includes/ Share on other sites More sharing options...
Handy PHP Posted September 24, 2009 Share Posted September 24, 2009 Use absolute path from root: This might be useful: <?php include $_SERVER['DOCUMENT_ROOT']."/lib/sample.lib.php"; ?> So you can move script anywhere in web-project tree without changes. Good luck, Handy PHP Quote Link to comment https://forums.phpfreaks.com/topic/175394-help-with-includes/#findComment-924249 Share on other sites More sharing options...
phpforsilk Posted September 24, 2009 Author Share Posted September 24, 2009 Sorry, but I tired that and it doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/175394-help-with-includes/#findComment-924270 Share on other sites More sharing options...
mikesta707 Posted September 24, 2009 Share Posted September 24, 2009 post code? Quote Link to comment https://forums.phpfreaks.com/topic/175394-help-with-includes/#findComment-924298 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.