why do some HTTP headers show up in $_SERVER? Why not $_GET or $_POST ???

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

    #1

    why do some HTTP headers show up in $_SERVER? Why not $_GET or $_POST ???


    I noticed this odd PHP function in an article about AJAX and Prototype:

    [color=blue]
    > http://www.sitepoint.com/article/pai...pt-prototype/2
    >
    > Prototype adds a custom HTTP header to all its AJAX requests so that your server
    > application can detect that it's an AJAX call, rather than a normal call. The header is:
    >
    > X-Requested-With: XMLHttpRequest
    >
    > Here's an example PHP function used to detect an AJAX call:
    >
    > function isAjax() {
    > return isset($_SERVER['HTTP_X_REQUEST ED_WITH']) &&
    > $_SERVER ['HTTP_X_REQUEST ED_WITH'] == 'XMLHttpRequest ';
    > }[/color]


    Most of the AJAX calls I've seen are GET or POST, so I expect them to
    show up in the $_GET or $_POST arrays. Why would this header show up in
    the $_SERVER array?

  • nospam@example.com

    #2
    Re: why do some HTTP headers show up in $_SERVER? Why not $_GET or $_POST ???


    lawrence k wrote:
    [color=blue]
    > Most of the AJAX calls I've seen are GET or POST, so I expect them to
    > show up in the $_GET or $_POST arrays. Why would this header show up in
    > the $_SERVER array?[/color]

    A HTTP header is not an extra parameter passed via GET or POST. See
    http://www.php.net/manual/en/function.header.php.

    Comment

    • John Dunlop

      #3
      Re: why do some HTTP headers show up in $_SERVER? Why not $_GET or $_POST ???

      lawrence k:
      [color=blue]
      > Most of the AJAX calls I've seen are GET or POST, so I expect them to
      > show up in the $_GET or $_POST arrays. Why would this header show up in
      > the $_SERVER array?[/color]

      GET and POST are just the names of two methods of sending an HTTP
      request, not to be confused with the PHP variables of the same name.
      The PHP variable $_GET makes available name=value pairs passed in the
      query part of the request-URL (even if the actual method is POST), and
      $_POST makes available name=value pairs passed in the body of the
      request. $_SERVER, on the other hand, makes available some but not all
      of the headers of the request.



      HTH.

      --
      Jock

      Comment

      Working...