I have cacheable dynamic content made in PHP 5.1.0+. I already send the correct headers (including Last-Modified and ETag) to clients.
I now want my script to be able to answer $_SERVER['HTTP_IF_MODIFIED_SINCE']
and $_SERVER['HTTP_IF_NONE_MATCH']
when present. When the conditions matches, I want to answer a HTTP 304 "Not Modified"
to clients.
What are the correct conditions? When exactly I issue a 304 instead of the whole content?
The accepted answer in question How to know when to send a 304 Not Modified response seems to issue this correctly but I have hard times to port that code to PHP 5.
Thank you!
If I could improve slightly on the original brilliant answer from Rich Bradshaw https://stackoverflow.com/users/16511/rich-bradshaw
This code is tweaked and now 100% passes the If-Modified-Since and If-None-Match checks. It also correctly formats the Last-Modified Date as original answer sends out +0000 on the end instead of GMT and adds the VARY header to the 304 response. You can test this at redbot.org