Page 1 of 1
Root-relative paths
Posted: Wed Mar 03, 2004 6:35 pm
by uberpolak
Any ideas why include('pages/' . $sec . '.php'); works fine, but include('/pages/' . $sec . '.php'); gives an error? The pages folder is in the document root, and if possible, it's going to be much easier for me to use root-relatives than try to figure out what folder I'm in all the time (user-friendly URLs).
Posted: Wed Mar 03, 2004 6:50 pm
by andre_c
from what I know, php doesn't really use the document root when using the slash, instead it uses the root of the system.
if you want to be able to include something no matter which document you are on, you should add it to include_path on your php.in file
i would recommend creating a directory with all files you need to include called globals or something similar on the root document of every website and adding ./globals to the include_path on php.ini
Posted: Wed Mar 03, 2004 8:17 pm
by McGruff
That must be an install folder under root - it can't be the doc root if "/path/to/file.php" doesn't work.
Check DocumentRoot in httpd.conf.
Posted: Thu Mar 04, 2004 4:44 am
by JayBird
you could do this for your includes, its what i do
Code: Select all
$BasePath = str_repeat("../", substr_count(dirname($_SERVER["SCRIPT_NAME"]), "/"));
require ($BasePath."ocdaintranet/includes/db_connection.php");
Mark
Posted: Thu Mar 04, 2004 2:31 pm
by andre_c
or this:
Code: Select all
include $_SERVER['DOCUMENT_ROOT'].'/pages/'. $sec. '.php';