By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,496 Members | 1,268 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,496 IT Pros & Developers. It's quick & easy.

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

P: n/a

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

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_REQUESTED_WITH']) &&
$_SERVER ['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
}

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?

Apr 7 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

lawrence k wrote:
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?


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

Apr 7 '06 #2

P: n/a
lawrence k:
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?


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.

http://www.php.net/manual/en/languag...predefined.php

HTH.

--
Jock

Apr 7 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.