![]() ![]() |
| kohenkatz |
Aug 24 2008, 02:13 AM
Post
#1
|
|
Group: Members Posts: 2 Joined: 24-August 08 Member No.: 6,489 |
I am using php includes to include a set of functions in all my pages.
However, some of these functions contain includes as well. example.com/index.php which includes: example.com/inc/functions.php which in turn includes: example.com/inc/dbcon.php The problem is that PHP looks for the second include file relative to the first file. So I would need to put "include('inc/dbcon.php');" in the second file. However, that makes it that I can no longer use these functions from any other directory. i.e. example.com/subf/index.php which includes: example.com/inc/functions.php which in turn includes: example.com/inc/dbcon.php will not work because it wants to do "include('../inc/dbcon.php');". What can I do about this? |
| Tom H. |
Aug 24 2008, 07:13 AM
Post
#2
|
|
Advanced Member ![]() ![]() ![]() ![]() Group: Members Posts: 103 Joined: 24-August 06 Member No.: 14 |
I had similar difficulty, but had success calling the nested include like this:
CODE <?php include('./path/from/web-root/inc/nested.incl'); ?> I can't find any documentation to support it, but it seems like the leading dot-slash indicates the web server document root. |
| kohenkatz |
Aug 24 2008, 01:08 PM
Post
#3
|
|
Group: Members Posts: 2 Joined: 24-August 08 Member No.: 6,489 |
I had similar difficulty, but had success calling the nested include like this: CODE <?php include('./path/from/web-root/inc/nested.incl'); ?> I can't find any documentation to support it, but it seems like the leading dot-slash indicates the web server document root. no. this would not work for me. The dot does not mean the web root, it means the current directory. In your case, the current directory happens to also be the web root. |
| pandy |
Aug 24 2008, 01:42 PM
Post
#4
|
|
Don't like donuts. Don't do MySpace. ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: WDG Moderators Posts: 7,207 Joined: 9-August 06 Member No.: 6 |
What about using the fully qualified URL (http://...)? I also think a system path works. That is, something like so:
CODE <?php include('/home/you/domains/example.com/inc/nested.incl'); ?> -------------------- “Never go to excess, but let moderation be your guide.”
– Cicero |
| Brian Chandler |
Aug 25 2008, 03:24 AM
Post
#5
|
|
Jocular coder ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 1,431 Joined: 31-August 06 Member No.: 43 |
I think the "proper" way is to have all the include files somewhere outside the document tree, then they can't be accidentally dished up by the web server.
But if not, use $_SERVER["DOCUMENT_ROOT"] to get to the document root. You do have a phpinfo() page you use, don't you? |
![]() ![]() |
|
Lo-Fi Version | Time is now: 21st November 2009 - 07:03 AM |