Root-relative paths
Moderator: General Moderators
Root-relative paths
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).
- andre_c
- Forum Contributor
- Posts: 412
- Joined: Sun Feb 29, 2004 6:49 pm
- Location: Salt Lake City, Utah
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
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
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.
Check DocumentRoot in httpd.conf.
Last edited by McGruff on Thu Mar 04, 2004 10:04 pm, edited 1 time in total.
you could do this for your includes, its what i do
Mark
Code: Select all
$BasePath = str_repeat("../", substr_count(dirname($_SERVER["SCRIPT_NAME"]), "/"));
require ($BasePath."ocdaintranet/includes/db_connection.php");- andre_c
- Forum Contributor
- Posts: 412
- Joined: Sun Feb 29, 2004 6:49 pm
- Location: Salt Lake City, Utah
or this:
Code: Select all
include $_SERVER['DOCUMENT_ROOT'].'/pages/'. $sec. '.php';