title: How to test for "If-Modified-Since" HTTP Header support
body: <p>Using PHP how can I accurately test that a remote website <strong>supports</strong> the "If-Modified-Since" HTTP header.</p>
  
  <p>From what I have read, if the remote file you GET has been modified since the date specified in the header request - it should return a 200 OK status.  If it hasn't been modified, it should return a 304 Not Modified.  </p>
  
  <p>Therefore my question is, what if the server <strong>doesn't</strong> support "If-Modified-Since" but still returns a 200 OK?</p>
  
  <p>There are a few tools out there that check if your website supports "If-Modified-Since" so I guess I'm asking how they work.</p>
  
  <p>Edit:</p>
  
  <p>I have performed some testing using Curl, sending the following;</p>
  
  <pre><code>curl_setopt($ch, CURLOPT_HTTPHEADER, array("If-Modified-Since: ".gmdate('D, d M Y H:i:s \G\M\T',time()+60*60*60*60)));
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
  curl_setopt($ch, CURLOPT_HEADER, true);
  curl_setopt($ch, CURLOPT_NOBODY, true);
  curl_setopt($ch, CURLOPT_AUTOREFERER, true);
  curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);
  curl_setopt($ch, CURLOPT_TIMEOUT, 4);
  </code></pre>
  
  <p>i.e. a date in the future google.com returns;</p>
  
  <pre><code>HTTP/1.0 304 Not Modified
  Date: Fri, 05 Feb 2010 16:11:54 GMT
  Server: gws
  X-XSS-Protection: 0
  X-Cache: MISS from .
  Via: 1.0 .:80 (squid)
  Connection: close
  </code></pre>
  
  <p>and if I send;</p>
  
  <pre><code>curl_setopt($ch, CURLOPT_HTTPHEADER, array("If-Modified-Since: ".gmdate('D, d M Y H:i:s \G\M\T',time()-60*60*60*60)));
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
  curl_setopt($ch, CURLOPT_HEADER, true);
  curl_setopt($ch, CURLOPT_NOBODY, true);
  curl_setopt($ch, CURLOPT_AUTOREFERER, true);
  curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);
  curl_setopt($ch, CURLOPT_TIMEOUT, 4);
  </code></pre>
  
  <p>i.e. a date in the past, google.com returns;</p>
  
  <pre><code>HTTP/1.0 200 OK
  Date: Fri, 05 Feb 2010 16:09:12 GMT
  Expires: -1
  Cache-Control: private, max-age=0
  Content-Type: text/html; charset=ISO-8859-1
  Server: gws
  X-XSS-Protection: 0
  X-Cache: MISS from .
  Via: 1.0 .:80 (squid)
  Connection: close
  </code></pre>
  
  <p>If I then send both to bbc.co.uk (which doesn't support it);</p>
  
  <p>The future one returns;</p>
  
  <pre><code>HTTP/1.1 200 OK
  Date: Fri, 05 Feb 2010 16:12:51 GMT
  Server: Apache
  Set-Cookie: BBC-UID=84bb66bc648318e367bdca3ad1d48cf627005b54f090f211a2182074b4ed92c40ForbSoft%20Web%20Diagnostics%20%28URL%20Validator%29; expires=Tue, 04-Feb-14 16:12:51 GMT; path=/; domain=bbc.co.uk;
  Accept-Ranges: bytes
  Cache-Control: max-age=0
  Expires: Fri, 05 Feb 2010 16:12:51 GMT
  Pragma: no-cache
  Content-Length: 111677
  Content-Type: text/html
  </code></pre>
  
  <p>The date in the past returns;</p>
  
  <pre><code>HTTP/1.1 200 OK
  Date: Fri, 05 Feb 2010 16:14:01 GMT
  Server: Apache
  Set-Cookie: BBC-UID=841b66ec44232cd91e81e88a014a3c5e50ed4e20c0e07174c4ff59675cd2fa210ForbSoft%20Web%20Diagnostics%20%28URL%20Validator%29; expires=Tue, 04-Feb-14 16:14:01 GMT; path=/; domain=bbc.co.uk;
  Accept-Ranges: bytes
  Cache-Control: max-age=0
  Expires: Fri, 05 Feb 2010 16:14:01 GMT
  Pragma: no-cache
  Content-Length: 111672
  Content-Type: text/html
  </code></pre>
  
  <p><strong>So my question still stands.</strong></p>