I have written a web app in PHP which makes use of Ajax requests (made using YUI.util.Connect.asyncRequest).
Most of the time, this works fine. The request is sent with an X-Requested-With value of XMLHttpRequest. My PHP controller code uses apache_request_headers() to check whether an incoming request is Ajax or not and all works well.
But not always. Intermittently, I'm getting a situation where the Ajax request is sent (and Firebug confirms for me that the headers on the request include an X-Requested-With of XMLHttpRequest) but apache_request_headers() is not returning that header in its list.
The output from when I var_dump the apache_request_headers() is as follows (note the lack of X-
'Host' => string 'peterh.labs.example.com' (length=26)
'User-Agent' => string 'Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.3) Gecko/2008101315 Ubuntu/8.10 (intrepid) Firefox/3.0.3' (length=105)
'Accept' => string 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' (length=63)
'Accept-Language' => string 'en-gb,en;q=0.5' (length=14)
'Accept-Encoding' => string 'gzip,deflate' (length=12)
'Accept-Charset' => string 'ISO-8859-1,utf-8;q=0.7,*;q=0.7' (length=30)
'Keep-Alive' => string '300' (length=3)
'Connection' => string 'keep-alive' (length=10)
'Referer' => string 'http://peterh.labs.example.com/qmail/' (length=40)
'Cookie' => string 'WORKFLOW_SESSION=55f9aff2051746851de453c1f776ad10745354f6' (length=57)
'Pragma' => string 'no-cache' (length=8)
'Cache-Control' => string 'no-cache' (length=8)
But Firebug tells me:
Request Headers:
Host peterh.labs.example.com
User-Agent Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.3) Gecko/2008101315 Ubuntu/8.10 (intrepid) Firefox/3.0.3
Accept text/html,application/xhtml+xml,application/xml;q=0.9,**;q=0.8
Accept-Language en-gb,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 300
Connection keep-alive
X-Requested-With XMLHttpRequest
Referer http://peterh.labs.example.com/qmail/
Cookie WORKFLOW_SESSION=55f9aff2051746851de453c1f776ad10745354f6
This mismatch is (apparently) intermittent when executing the same code. But I don't believe in "intermittent" when it comes to software! Help!