Page 1 of 1

Setting Your Include Path

Posted: Wed Jul 30, 2008 2:56 am
by omniuni
As you include things, the relative include paths are relative to the current document. I have tried re-writing the script with absolute paths, but that did not work. Can I set a script to execute setting the current path relative to it?

In other words

I have index.php, a folder "includes" and in there, "db.inc" and "readdb.inc". From index.php, I want to include "includes/readdb.inc", and I want to be able to access "db.inc" from "readdb.inc" using the relative path simply "db.inc".

Thanks for any help...

-OmniUni

Re: Setting Your Include Path

Posted: Wed Jul 30, 2008 3:02 am
by Phoenixheart
No, I don't think so. The path is relative to the executing script, in this case index.php. In other words, once you include db.inc into index.php, it becomes a part of index.php, so a reference to "readdb.inc" will look in the same folder of index.php... and fails :)

Re: Setting Your Include Path

Posted: Wed Jul 30, 2008 3:27 am
by omniuni
Thank you.

Apparently it is something about the way the script I am using is written; I went through and set relative paths as from the executing script by hand, and it worked.

I had tried creating a variable to use as the path, and that failed miserably, for some reason.

Thanks again,

OmniUni

Re: Setting Your Include Path

Posted: Wed Jul 30, 2008 4:41 pm
by andychamberlainuk
if you want absolute links, you must include your entire server path (whether it be local or on a server)

Here's the code I use: -

Code: Select all

 
include_once ($_SERVER['DOCUMENT_ROOT'] . "/classes/mysql.php");
 
By using this, you can be sure that you are including the correct documents EVERY time!