473,396 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Parsing $_SERVER array problem

CPD
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
Jul 17 '05 #1
4 2482
CPD wrote:
I can't parse $_SERVER when using the alphabetic key instead of the numeric
index of the array.
I find this very strange!

My $_SERVER array (and every other $_SERVER array anywhere I've seen)
does not have numeric indexes.

1 echo "REMOTE_ADDR direct : ". $_SERVER['REMOTE_ADDR'] . "<br>\n";
<snip>
Here is the corresponding output, with notes in square brackets:

1 REMOTE_ADDR direct : [note REMOTE_ADDR was not resolved here]


<snip>

What are the real contents of $_SERVER['REMOTE_ADDR']?
I'm pretty sure it should be an IP address, not a [resolved] host name.

--
Mail sent to my "From:" address is publicly readable at http://www.dodgeit.com/
== ** ## !! !! ## ** ==
TEXT-ONLY mail to the complete "Reply-To:" address ("My Name" <my@address>) may
bypass the spam filter. I will answer all pertinent mails from a valid address.
Jul 17 '05 #2
In article <aeVod.384689$wV.23482@attbi_s54>, an*******@nospam.pls
says...
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!


You will probably have better success inserting phpinfo() in your code
and checking to see what the $_SERVER environment have defined as names.
--
AJ
Treehouse Networks abuse@
www.treenetnz.com
Jul 17 '05 #3
CPD
REMOTE_ADDR does contain a numeric IP address, and I did not expect it to
have a host name. What I meant by 'resolve' was actually getting the IP
address value using the construct $_SERVER['REMOTE_ADDR']. I just found out
that I am able to get the IP address via the old superglobal
$HTTP_SERVER_VARS['REMOTE_ADDR'], but not via the newer
$_SERVER['REMOTE_ADDR'].

phpinfo() does expose all the values in each of the superglobals.

Is there some PHP setting required to use $_SERVER?
"Pedro Graca" <he****@dodgeit.com> wrote in message
news:sl*******************@ID-203069.user.uni-berlin.de...
CPD wrote:
I can't parse $_SERVER when using the alphabetic key instead of the numeric index of the array.
I find this very strange!

My $_SERVER array (and every other $_SERVER array anywhere I've seen)
does not have numeric indexes.

1 echo "REMOTE_ADDR direct : ". $_SERVER['REMOTE_ADDR'] . "<br>\n";


<snip>
Here is the corresponding output, with notes in square brackets:

1 REMOTE_ADDR direct : [note REMOTE_ADDR was not resolved here]


<snip>

What are the real contents of $_SERVER['REMOTE_ADDR']?
I'm pretty sure it should be an IP address, not a [resolved] host name.

--
Mail sent to my "From:" address is publicly readable at

http://www.dodgeit.com/ == ** ## !! !! ## ** == TEXT-ONLY mail to the complete "Reply-To:" address ("My Name" <my@address>) may bypass the spam filter. I will answer all pertinent mails from a valid

address.
Jul 17 '05 #4
[ Please don't toppost. ]
[ See http://www.greenend.org.uk/rjk/2000/06/14/quoting.html ]

CPD top-posted:
I just found out
that I am able to get the IP address via the old superglobal
$HTTP_SERVER_VARS['REMOTE_ADDR'], but not via the newer
$_SERVER['REMOTE_ADDR'].

phpinfo() does expose all the values in each of the superglobals.
This is getting stranger and stranger.

Did you try the phpinfo() in the same script that is giving you trouble,
right after the troublesome line?
Is there some PHP setting required to use $_SERVER?


I don't think so.

What's your PHP version?
How are you using it (as a module or as CGI)?
--
Mail sent to my "From:" address is publicly readable at http://www.dodgeit.com/
== ** ## !! !! ## ** ==
TEXT-ONLY mail to the complete "Reply-To:" address ("My Name" <my@address>) may
bypass the spam filter. I will answer all pertinent mails from a valid address.
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: chops | last post by:
I need the path of the script that is running. Unfortunately it is not in the $_SERVER array when running a script through the CLI. Through a browser I can strip the script name off, e.g...
4
by: Joshua Beall | last post by:
Hi All, I've seen many references to the $_SERVER variable, which is set to the string 'on' when the client is connected via HTTPS rather than regular HTTP. However, I have been unable to find...
3
by: Joshua Beall | last post by:
Hi All, What is the difference between $_SERVER and $_SERVER, and which is better to use? According to the CGI 1.1 spec (http://hoohoo.ncsa.uiuc.edu/cgi/env.html), SCRIPT_NAME is not...
3
by: millertimebjm | last post by:
I have a login that uses header information to authenticate users. header('WWW-Authenticate: Basic realm="my site", FALSE'); These values go into the php_auth_user and PHP_AUTH_PW in $_SERVER...
1
by: Michael Brennan-White | last post by:
If I submit my for using a get action the resulting page loads . If I use a post action I get an error page saying "The page cannot be found". I am calling the originating page!!! This happens...
0
by: Marc van Boven | last post by:
I'm stuck with the following problem: My nusoap-client calls a server-function giveCombination(). The function giveCombination should return something like array( => array( 'a_id' => 6,...
4
by: Stefan Bellon | last post by:
Hi all! I want to parse the contents of an .htaccess file from within PHP. The contents of the .htaccess file looks like this: <Files foobar.tar.gz> AuthType Basic AuthUserFile /foobar...
7
by: Dynamo | last post by:
I am using values stored an $_POST array to display records from a table before asking the user if he is sure he wants to delete them. If the user confirms then the records are deleted. Without...
7
by: Puneet | last post by:
I really loosing sleep over this one. I have php 4.4 running on Apache 2.... php works fine. phpinfo() retuns everything as it should.. However when I try to print anything using $_SERVER e.g...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.