10.7.14
I'm trying to access one of the standard CGI
variables (such as $DOCUMENT_ROOT or $HTTP_REFERER) in a user-defined
function, and it can't seem to find it. What's wrong?
It's important to realize that the PHP directive register_globals also affects
server and environment variables. When register_globals = off (the
default is off since PHP 4.2.0),
$DOCUMENT_ROOT
will not exist. Instead, use
$_SERVER['DOCUMENT_ROOT']
. If register_globals = on then the variables
$DOCUMENT_ROOT
and
$GLOBALS['DOCUMENT_ROOT']
will also exist.
If you're sure register_globals = on and wonder why
$DOCUMENT_ROOT
isn't available inside functions,
it's because these are like any other variables and would
require
global $DOCUMENT_ROOT
inside the
function. See also the manual page on
variable scope . It's
preferred to code with register_globals = off.
Note | Superglobales : disponiblité
Depuis PHP 4.1.0, les tableaux superglobaux tels que
$_GET
,
$_POST
et
$_SERVER
, etc... sont disponibles. Pour plus d'informations, lisez la section superglobals
|
|