Re: Problems with environment variables
| From: | Hardy Merrill | Date: | Thu, 16 Nov 2000 12:38:33 +0000 |
| Subject: | Re: Problems with environment variables | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-25682@lists.php.net to get a copy of this message | ||
kod811 [kod811@bigfoot.com] wrote:
> Hello all,
>
> I've been having problems getting values out of the env vars $HTTP_HOST,
> $REMOTE_ADDR, $REMOTE_PORT, etc. I've got the following code to illustrate
> my problem:
>
>
> <?php
>
> function dummyfunc() {
> echo "dummyfunc.REMOTE_ADDR==>" . $REMOTE_ADDR . "<br>";
> echo "dummyfunc.REMOTE_PORT==>" . $REMOTE_PORT . "<br>";
> echo "dummyfunc.REMOTE_ADDR:REMOTE_PORT==>" . $REMOTE_ADDR . ":" .
> $REMOTE_PORT . "<br>";
> echo "dummyfunc.HTTP_HOST==>" . $HTTP_HOST . "<br>";
> }
Within functions, you when using environment variables, you need
to declare those variables "global", like:
function dummyfunc() {
global $REMOTE_ADDR, $REMOTE_PORT, $HTTP_HOST;
.
.
.
}
HTH.
--
Hardy Merrill
Mission Critical Linux, Inc.
http://www.missioncriticallinux.com
>
> echo "main.REMOTE_ADDR==>" . $REMOTE_ADDR . "<br>";
> echo "main.REMOTE_PORT==>" . $REMOTE_PORT . "<br>";
> echo "main.REMOTE_ADDR:REMOTE_PORT==>" . $REMOTE_ADDR . ":" .
$REMOTE_PORT
> . "<br>";
> echo "main.HTTP_HOST==>" . $HTTP_HOST . "<br>";
>
> dummyfunc();
>
> ?>
>
>
>
>
> When viewed through a browser, I get the following output:
>
>
> main.REMOTE_ADDR==>132.232.341.111
> main.REMOTE_PORT==>4444
> main.REMOTE_ADDR:REMOTE_PORT==>132.232.341.111:4444
> main.HTTP_HOST==>server1.blarg.com
> dummyfunc.REMOTE_ADDR==>
> dummyfunc.REMOTE_PORT==>
> dummyfunc.REMOTE_ADDR:REMOTE_PORT==>:
> dummyfunc.HTTP_HOST==>
>
>
>
> What am I doing wrong? Am I missing something?
>
> Thank you for your response in advance.
>
> kod811
>