Question

I've a fair bit of experience with HTTP, headers, browsers, javascript, PHP, and all this related hoo-hah, but this one has me stumped.

I've written a Javascript RESTful frontend using the Dojo javascript toolkit. One component of it is a RESTful store that polls the backend for new data items, passing the If-Modified-Since header to the server. The backend then responds with all items created or updated since that time. My backend is PHP and reads the $_SERVER['HTTP_IF_MODIFIED_SINCE'] value, parses it, and processing continues.

This works flawlessly on my localhost (Ubuntu 13.05, apache2 2.4.6 PHP 5.5.3) in both Chrome and Firefox. However, on our production server (Centos 6.5 apache2 2.2.23 PHP 5.3.17), Chrome works fine, but Firefox has a problem.

What I see is that Firefox sends the If-Modified-Since header correctly and with normal date format, however, the PHP $_SERVER variable contains HTTP_IF_MODIFIED_SINCE but the value appears to be empty, and getallheaders() returns an array without that header, but with all other headers. My question is, what could be causing this, and how should it be fixed?

Googling on this subject leads me to lots of people who don't know how to use Last-Modified to cause the browser to send If-Modified-Since in the first place, or how to use it if it is sent. I cannot find anyone else with the problem that it is sent, but not received on the server, for just one type of browser.

I cannot capture the headers from the Firefox Network Monitor as text easily (well done Mozilla) but trust me, If-Modified-Since is there, with value e.g. Sat, 08 Feb 2014 10:29:14 GMT, nestled in between Accept-Encoding and Content-Type.

Code on the backend:

$l->log('test for header from user agent ' . $_SERVER['HTTP_USER_AGENT'] . '...');
$headers = getallheaders();
foreach ($headers as $name => $value) {
        $l->log("Saw header $name => $value");
}
if (array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER)) {
        $mod = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
        $l->log('header exists: (' . $mod . ')');
        // handle here
} else {
        $l->log('No IF_MODIFIED_SINCE found.');
}

example logging:

Feb 08 10:33:24  [info] test for header from user agent Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:26.0) Gecko/20100101 Firefox/26.0...
Feb 08 10:33:24  [info] Saw header Host => www.premierrange.co.uk
Feb 08 10:33:24  [info] Saw header User-Agent => Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:26.0) Gecko/20100101 Firefox/26.0
Feb 08 10:33:24  [info] Saw header Accept => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Feb 08 10:33:24  [info] Saw header Accept-Language => en-US,en;q=0.5
Feb 08 10:33:24  [info] Saw header Accept-Encoding => gzip, deflate
Feb 08 10:33:24  [info] Saw header Content-Type => application/x-www-form-urlencoded
Feb 08 10:33:24  [info] Saw header X-Requested-With => XMLHttpRequest
Feb 08 10:33:24  [info] Saw header Referer => http://www.premierrange.co.uk/obfuscated
Feb 08 10:33:24  [info] Saw header Cookie => obfuscated
Feb 08 10:33:24  [info] Saw header Connection => keep-alive
Feb 08 10:33:24  [info] Saw header Via => HTTP/1.1 NetScaler, HTTP/1.1 NetScaler
Feb 08 10:33:24  [info] header exists: ()
Feb 08 10:33:24  [info] HTTP_IF_MODIFIED_SINCE  strtotime gives  turning that into date string gives 1970-01-01 01:00:00

As you can see, an array_key_exists test returns true, but the value is empty, yet getallheaders() appears to return an array of headers that does not include If-Modified-Since.

Any clues, before I tear even more hair out?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top