Does $_SERVER[‘HTTP_X_REQUESTED_WITH’] exist in PHP or not?

The variables in $_SERVER are not really part of PHP, which is why you won’t find them in the PHP documentation. They are prepared by the Web server which passes them on to the scripting language.

As far as I know, the X-Requested-With is sent by the Ajax functions of most major Frameworks but not all (Dojo, for example, added it only two years ago: #5801). As such, and taking into considerations @bobince’ comments, it’s safe to say it’s not generally a 100% reliable method to determine whether a request is an AJAX request or not.

The only 100% secure way is to send a pre-defined flag (e.g. a GET variable) along with the request and for the receiving page to check for the presence of that flag.

Leave a Comment