antonyfal Posted October 7, 2011 Share Posted October 7, 2011 Hello, Is this a sound explanation of require and include.. Lets say i have "X" application with an index.php file. in a folder on my domain like so: www.xxx.com/Application X folder/index.php. // the index.php calls to multiple files with-in the "Application X folder" and database. What if i move the index.php to another location all together like so: http://www.xxx.com/notXsubfolder1/notXsubfolder2/notXsubfolder3/index.php //the X application index file.. and then edit the require and include links in the index.php file to paths like this (just example might not be accurate): require_once '../../../../application X Folder/include/required_file.php'; My question:?? What i want to know is: if the required_file.php has includes of its own, will it take the includes that it requires from its original folder where the Required_file.php is located? or will its paths change the the new index.php location?? . Quote Link to comment https://forums.phpfreaks.com/topic/248658-important-is-my-logic-sound-a-question-about-include-and-require/ Share on other sites More sharing options...
jcbones Posted October 7, 2011 Share Posted October 7, 2011 An include that has a relative file path, will be relative to the file calling the include (which would be the script that you call, ie. index.php). The greatest way to include a file is with an absolute file path. That will eliminate relative file path problems. I do this with a Constant in my main Config file. Once you get in the habit, all of your relative woes will be behind you. <?php define('INCLUDES_ABSOLUTE_PATH','home/absolute/path/to/includes'); include INCLUDES_ABSOLUTE_PATH . '/required_file.php'; Now, if you move your files, you only have to change it in one location. The config file. Quote Link to comment https://forums.phpfreaks.com/topic/248658-important-is-my-logic-sound-a-question-about-include-and-require/#findComment-1277072 Share on other sites More sharing options...
antonyfal Posted October 7, 2011 Author Share Posted October 7, 2011 Thanks for replying. So basically its the hard way for me now :'( , but I do understand from your explanation... Thanks again Rgs Antony Quote Link to comment https://forums.phpfreaks.com/topic/248658-important-is-my-logic-sound-a-question-about-include-and-require/#findComment-1277086 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.