Candid’s brain

PHP sending strange Last-Modified headers

At the moment I am trying to implement a proper handling of Last-Modified and If-Modified-Since headers (RFC 2616 is really useful, by the way) and have experienced very strange behaviour of PHP during sending Last-Modified headers.

One smaller thing that occured to me was session_start() to send Cache-Control, Pragma, and Expires headers. In PHP, you can simply remove them from the sent headers by calling header("Pragma: ", true);, for example.

Well, I set the Last-Modified header to some date("r") value, and it happened that my browser always received the time of the request (in GMT instead of CET) instead of the time I sent. When I sent "Last-Modified: 0", this was converted to a correct HTTP GMT date string. Sending the same thing as X-Last-Modified for example sent exactly what I set although. (By the way, HTTP trace works better and faster than Firefox’s Web Developer Toolbar.)

It seems to be that PHP tries to parse and correct the Last-Modified header before sending it, and this “feature” is a little buggy. I fixed the problem by simply using gmdate("r") instead. My PHP version is 5.2.5-pl1-gentoo, by the way.

Filed under bugs

Comments are closed.