I can't parse $_SERVER when using the alphabetic key instead of the numeric
index of the array. Below is some of the line-numbered code, followed by
the corresponding output. For this posting, IP address and domains shown
are fictitious. Note how the REMOTE_HOST is resolved by gethostbyaddr()
using a hard-coded IP address or the array index "10", but it fails
completely when the literal key REMOTE_ADDR is used.
Any help with this will be greatly appreciated. Thanks!
Here is the numbered PHP code fragment:
1 echo "REMOTE_ADDR direct : ". $_SERVER['REMOTE_ADDR'] . "<br>\n";
2 echo "REMOTE_HOST by var name: ". gethostbyaddr($_SERVER['REMOTE_ADDR']) .
"<br>\n";
3 echo "REMOTE_HOST hard-coded : ". gethostbyaddr('20.1.22.40') . "<br>\n";
4 echo "REMOTE_HOST by index 9 : ". gethostbyaddr($_SERVER[10]) . "<br>\n";
5 while ( list( $key, $val ) = each( $_SERVER ) ) { echo " $key => $val
<br>\n"; }
Here is the corresponding output, with notes in square brackets:
1 REMOTE_ADDR direct : [note REMOTE_ADDR was not resolved here]
2 Warning: gethostbyaddr(): Address is not a valid IPv4 or IPv6 address in
env.php on line 2
REMOTE_HOST by var name: [again REMOTE_ADDR was not resolved here]
3 REMOTE_HOST hard-coded : c-20-1-22-40.client.comcast.net
4 REMOTE_HOST by index 9 : c-20-1-22-40.client.comcast.net
5 [ below is output from while loop]
0 =>
1 => */*
2 => /bin:/sbin:/usr/bin:/usr/sbin
3 => /env.php
4 => /env.php
5 => /env.php
6 => /usr/local/psa/home/vhosts/gldomain.com/httpdocs
7 => /usr/local/psa/home/vhosts/gdomain.com/httpdocs/env.php
8 => /usr/local/psa/home/vhosts/gldomain.com/httpdocs/env.php
9 => 204.146.241.180
10 => 20.1.22.40
11 => 80
12 => 1353
13 => Apache/1.3.27 Server at www.gldomain.com Port 80
14 => Apache/1.3.27 (Unix) mod_python/2.7.8 Python/2.2.2
mod_webapp/1.2.0-dev mod_perl/1.27 mod_throttle/3.1.2 PHP/4.3.2
FrontPage/5.0.2.2510 mod_ssl/2.8.14 OpenSSL/0.9.7c
15 => CGI/1.1
16 => GET
17 => HTTP/1.1
18 => Keep-Alive
19 => Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)
20 => QaQZes2T974AAKlnBWg
21 => cs@gldomain.com
22 => 0
23 => en-us
24 => gzip, deflate
25 => www.gldomain.com
26 => www.gldomain.com
27 => Array