leefentress Posted September 3, 2008 Share Posted September 3, 2008 I guess I just never learned the best practice for includes and include paths. I've got this silly messy code I'm trying to replace with something simple that works well. <?php $mypath01 = '/Includes'; $mypath02 = './Includes'; $mypath03 = '../Includes'; $mypath04 = '../../Includes'; $mypath05 = '../../../Includes'; $mypath06 = '../../../../Includes'; $mypath07 = '.'; $mypath08 = './'; $mypath09 = '../'; $mypath10 = '../../'; $mypath11 = '../../../'; $mypath12 = '../../../../'; set_include_path(get_include_path() . PATH_SEPARATOR . $mypath01 . PATH_SEPARATOR . $mypath02 . PATH_SEPARATOR . $mypath03 . PATH_SEPARATOR . $mypath04 . PATH_SEPARATOR . $mypath05 . PATH_SEPARATOR . $mypath06 . PATH_SEPARATOR . $mypath07 . PATH_SEPARATOR . $mypath08 . PATH_SEPARATOR . $mypath09 . PATH_SEPARATOR . $mypath10 . PATH_SEPARATOR . $mypath11 . PATH_SEPARATOR . $mypath12); ?> I have so many pages nested at different levels in various folders and subfolders, I couldn't figure out an easy way for them all to find the includes they were supposed to be including so I would get errors saying the thing to be included couldn't be found. So then I set up that code to set the include path to look at various levels above itself and what not, and it works, but I don't like it. So then I wondered, is there a way to set more of a static location for it to always know to look to by using like the path from the home directory where in my case it would be like home/galilee/public_html/includes. If that would work, any idea what I could do for my local copy since it doesn't have the same structure with the home/galilee/public_html stuff? Quote Link to comment https://forums.phpfreaks.com/topic/122557-is-it-possible-to-set-include-path-to-like-homesitepublic_htmlincludes/ Share on other sites More sharing options...
lemmin Posted September 3, 2008 Share Posted September 3, 2008 $_SERVER['DOCUMENT_ROOT'] might be what you want. Or you can just use a local path on the server: c:\webserver\home\galilee\public_html\includes. Quote Link to comment https://forums.phpfreaks.com/topic/122557-is-it-possible-to-set-include-path-to-like-homesitepublic_htmlincludes/#findComment-632772 Share on other sites More sharing options...
wildteen88 Posted September 3, 2008 Share Posted September 3, 2008 Agreed with lemmin, use $_SERVER['DOCUMENT_ROOT'] before using includes, eg define('INC', $_SERVER['DOCUMENT_ROOT'] . '/Includes/'); Then when ever you want to include a file from your includes folder, just do include INC . 'file.php'; You do not to to configure your the include_path. Quote Link to comment https://forums.phpfreaks.com/topic/122557-is-it-possible-to-set-include-path-to-like-homesitepublic_htmlincludes/#findComment-632907 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.