Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Im trying to access one of the standard CGI variables (such as $DOCUMENT_ROOT or $HTTP_REFERER) in a user-defined function, and it can seem to find it. Whats wrong?

0
Posted

Im trying to access one of the standard CGI variables (such as $DOCUMENT_ROOT or $HTTP_REFERER) in a user-defined function, and it can seem to find it. Whats wrong?

0

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: Superglobals: availability note Superglobal arrays such as $_GET, $_POST, and $_SERVER, etc. are available as of PHP 4.1.0.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.