php $DOCUMENT_ROOT in include
Loren Chandler
pluglist at plug.org
Wed Apr 23 13:29:26 MDT 2003
$DOCUMENT_ROOT is likely setup by PHP, but it gets its value from a webserver
environment variable, so perhaps the environment variable is no longer being
provided at all by the webserver or there is something else in the settings that
is keeping PHP from being able to access it. Here is a little block of Perl
(sorry, not going to bother with the PHP equivalent) you can stick in a simple
script to print to your browser the available environment variables:
while(($ekey, $eval) = each(%ENV)){
print "$ekey : $eval<br>\n";
if ($ekey eq 'PATH') {
$path = $eval;
}
}
The document root variable that I get from this on Apache 1.3.x is called
DOCUMENT_ROOT and looks something like this through that bit of code:
DOCUMENT_ROOT : /usr/local/etc/httpd/htdocs
Another way in PHP to get a specific environment variable is like this:
$docroot = getenv("DOCUMENT_ROOT");
-Loren
-----Original Message-----
From: pluglist-admin at plug.org [mailto:pluglist-admin at plug.org]On Behalf
Of Wade Preston Shearer
Sent: Wednesday, April 23, 2003 12:57 PM
To: PLUG POST
Subject: php $DOCUMENT_ROOT in include
a php question.
a few months back, someone showed me how to use "$DOCUMENT_ROOT within
an include, like...
<?php @readfile($DOCUMENT_ROOT."/includes/file.inc"; ?>
...or...
<?php include("$DOCUMENT_ROOT/includes/file.inc"; ?>
this has been working great.
i just upgraded one of my servers to apache 2 however and it stopped
working. i have debugged to the point where in know that it is the
"$DOCUMENT_ROOT" part that isn't working.
i checked "httpd.conf" and "php.ini" and everything is in order
(including "allow_url_fopen").
then, curiously, i added...
<?php $DOCUMENT_ROOT = "/path/to/doc/root"; ?>
...before the includes... and WHA-LA! they work.
so... i gather then, that the part that isn't working is that is isn't
finding document root and that is why the includes are not working.
before i go further... let me ask a question...
i assumed that $DOCUMENT_ROOT was a "set" variable. by "set," i mean on
that is set by the "PHP guys," like $PHP_SELF. i thought that it was
built-in and that's how it got it's value. but, from the test that
tried, defining a value for the $DOCUMENT_ROOT variable, it makes me
wonder...
is the variable defined by the PHP module (part of the
package/brains/guts/whatever)?
or is it defined by the user... as part of either a conf/ini file or
even in a page/script?
so... my final question then... if the variable _is_ set by the user...
where?
-wade preston shearer
.===================================.
| This has been a P.L.U.G. mailing. |
| Don't Fear the Penguin. |
`==================================='
More information about the PLUG
mailing list