Darkmatter5 Posted March 13, 2009 Share Posted March 13, 2009 How can I change the following code so that regardless of where the code is directory wise on the site, it'll always push all the way back to the root of the site directory structure to find the files? I tried this, but didn't work. $color="white"; echo "<link href='$_SERVER[DOCUMENT_ROOT]/library/" .$color. "config.css' rel='stylesheet' type='text/css'> <link href='$_SERVER[DOCUMENT_ROOT]/library/" .$color. "divs.css' rel='stylesheet' type='text/css'> <link href='$_SERVER[DOCUMENT_ROOT]/library/" .$color. "forms.css' rel='stylesheet' type='text/css'> <link href='$_SERVER[DOCUMENT_ROOT]/library/" .$color. "links.css' rel='stylesheet' type='text/css'> <link href='$_SERVER[DOCUMENT_ROOT]/library/" .$color. "tables.css' rel='stylesheet' type='text/css'> <link href='$_SERVER[DOCUMENT_ROOT]/library/" .$color. "nav.css' rel='stylesheet' type='text/css'>"; Quote Link to comment https://forums.phpfreaks.com/topic/149292-help-with-require_once-and-include-commands/ Share on other sites More sharing options...
samshel Posted March 13, 2009 Share Posted March 13, 2009 not sure..try this. echo "<link href='/library/" .$color. "config.css' rel='stylesheet' type='text/css'> Quote Link to comment https://forums.phpfreaks.com/topic/149292-help-with-require_once-and-include-commands/#findComment-783997 Share on other sites More sharing options...
PFMaBiSmAd Posted March 13, 2009 Share Posted March 13, 2009 $_SERVER['DOCUMENT_ROOT'] is a file path on the server. It has no meaning when used in a link (or anything else that is rendered in a browser.) A leading slash / on a relative link refers to the domain root. Quote Link to comment https://forums.phpfreaks.com/topic/149292-help-with-require_once-and-include-commands/#findComment-783999 Share on other sites More sharing options...
samshel Posted March 13, 2009 Share Posted March 13, 2009 A leading slash / on a relative link refers to the domain root. Correct ! i thought thats what he is looking for. Quote Link to comment https://forums.phpfreaks.com/topic/149292-help-with-require_once-and-include-commands/#findComment-784002 Share on other sites More sharing options...
Darkmatter5 Posted March 16, 2009 Author Share Posted March 16, 2009 I just realized I didn't actually ask anything in regards to require or include. The answers to my first question worked great, so here's a new one. Here's an example directory structure public_html (folder) index.php library (folder) funcs.php forums (folder) index.php library (folder) forum_funcs.php public_html/index.php <?php require_once('/library/funcs.php'); ?> public_html/forums/index.php <?php require_once('/library/funcs.php'); require_once('/library/forum_funcs.php'); ?> This obviously produces an error in public_html/forums/index.php where it reports it can't find '/library/funcs.php'. How can I change the code for it to find the file? Quote Link to comment https://forums.phpfreaks.com/topic/149292-help-with-require_once-and-include-commands/#findComment-785811 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.