Parsing $_SERVER array problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CPD

    Parsing $_SERVER array problem

    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_ADD R direct : ". $_SERVER['REMOTE_ADDR'] . "<br>\n";
    2 echo "REMOTE_HOS T by var name: ". gethostbyaddr($ _SERVER['REMOTE_ADDR']) .
    "<br>\n";
    3 echo "REMOTE_HOS T hard-coded : ". gethostbyaddr(' 20.1.22.40') . "<br>\n";
    4 echo "REMOTE_HOS T 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.comca st.net
    4 REMOTE_HOST by index 9 : c-20-1-22-40.client.comca st.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 => QaQZes2T974AAKl nBWg
    21 => cs@gldomain.com
    22 => 0
    23 => en-us
    24 => gzip, deflate
    25 => www.gldomain.com
    26 => www.gldomain.com
    27 => Array


  • Pedro Graca

    #2
    Re: Parsing $_SERVER array problem

    CPD wrote:[color=blue]
    > I can't parse $_SERVER when using the alphabetic key instead of the numeric
    > index of the array.[/color]

    I find this very strange!

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

    [color=blue]
    > 1 echo "REMOTE_ADD R direct : ". $_SERVER['REMOTE_ADDR'] . "<br>\n";[/color]

    <snip>
    [color=blue]
    > Here is the corresponding output, with notes in square brackets:
    >
    > 1 REMOTE_ADDR direct : [note REMOTE_ADDR was not resolved here][/color]

    <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.

    Comment

    • TreeNet Admin

      #3
      Re: Parsing $_SERVER array problem

      In article <aeVod.384689$w V.23482@attbi_s 54>, anonymous@nospa m.pls
      says...[color=blue]
      > 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!
      >[/color]

      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@

      Comment

      • CPD

        #4
        Re: Parsing $_SERVER array problem

        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_VA RS['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" <hexkid@dodgeit .com> wrote in message
        news:slrncq8t4g .vuv.hexkid@ID-203069.user.uni-berlin.de...[color=blue]
        > CPD wrote:[color=green]
        > > I can't parse $_SERVER when using the alphabetic key instead of the[/color][/color]
        numeric[color=blue][color=green]
        > > index of the array.[/color]
        >
        > I find this very strange!
        >
        > My $_SERVER array (and every other $_SERVER array anywhere I've seen)
        > does not have numeric indexes.
        >
        >[color=green]
        > > 1 echo "REMOTE_ADD R direct : ". $_SERVER['REMOTE_ADDR'] . "<br>\n";[/color]
        >
        > <snip>
        >[color=green]
        > > Here is the corresponding output, with notes in square brackets:
        > >
        > > 1 REMOTE_ADDR direct : [note REMOTE_ADDR was not resolved here][/color]
        >
        > <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[/color]
        http://www.dodgeit.com/[color=blue]
        > == ** ## !! !! ##[/color]
        ** ==[color=blue]
        > TEXT-ONLY mail to the complete "Reply-To:" address ("My Name"[/color]
        <my@address>) may[color=blue]
        > bypass the spam filter. I will answer all pertinent mails from a valid[/color]
        address.


        Comment

        • Pedro Graca

          #5
          Re: Parsing $_SERVER array problem

          [ Please don't toppost. ]
          [ See http://www.greenend.org.uk/rjk/2000/06/14/quoting.html ]

          CPD top-posted:[color=blue]
          > I just found out
          > that I am able to get the IP address via the old superglobal
          > $HTTP_SERVER_VA RS['REMOTE_ADDR'], but not via the newer
          > $_SERVER['REMOTE_ADDR'].
          >
          > phpinfo() does expose all the values in each of the superglobals.[/color]

          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?
          [color=blue]
          > Is there some PHP setting required to use $_SERVER?[/color]

          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.

          Comment

          Working...