Jump to content

IMPORTANT!! Is my logic sound?? a question about include, and require


antonyfal
 Share

Recommended Posts

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??

 

.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.