# Thread: problem of require_once() with relative path.. is it a bug or normal behaviour

1. ## problem of require_once() with relative path.. is it a bug or normal behaviour

say if i do an include within an include an if i use relative paths it does not work.

HTML Code:
i have directory structure as follows:
<pre>
c:\web -- index.php
c:\web\framework --- errorhandler(folde),debugger (folder), index.php

c:\web\framework\errorhandler -- class.error.php
</pre>
1) c:\web\index.php -- include("framework/include.php") //correct

2) c:\web\include.php -- include("errorhandler/class.error.php //correct

3) c:\web\framework\errorhandler\class.error.php -- a) include("../include.php")//wrong error saying cannot open dtream
b) include("include.php")/right

3(b)should be wrong but in actual its viceversa.
3(a)is wrong and 3(b) is right

is it a bug or is it supposed to be like this.

2. Its kind of hard to explain this.....

-->blocks
-->templates
index.php

Say, if you have index.php

PHP Code:
<?php
?>

PHP Code:
<?php
?>
Becuase you inlcude the header.php in the index.php file then all the include in the header.php file need to be in relation to where files are stored in comparison to the index.php

I hope this makes sense.

Mark

3. so what i understood is position in require or anything is relative to where we are including the file not the actual position. RIGHT??

so, does it mean we should use absolute path because say we are including one file blocks/head.php which is relative to it. but it might not work if its not relative to index.php at the same path. RIGHT???

or should i use ini_set to reflect the different locations
or any other solution to work over this

4. Hello,

If you use absolute paths then try and use something like \$_SERVER['DOCUMENT_ROOT'] and the include in relation to that. That might help you.

Mark

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•