1. <?php
  2. $content_type = "text/css"; // File's content type you're serving dynamically
  3.  
  4. $if_mod = $_SERVER['HTTP_IF_MODIFIED_SINCE']; // Depending on your server, this variable may be differently named
  5. $actual_last_mod = gmdate("U", (filemtime(__FILE__)) );
  6. $if_last_mod_sent = strtotime($if_mod);
  7.  
  8. if (strlen($if_mod) > 2) { // if-last-modified header sent
  9. if ($actual_last_mod > $if_last_mod_sent) { // Need fresh results
  10. header("Content-Type: {$content_type}");
  11. header("Last-modified: " . gmdate("D, d M Y H:i:s", (filemtime(__FILE__)) ) . " GMT" );
  12. header("Comment: Need fresh results");
  13. }
  14. else { // Have latest results
  15. header("HTTP/1.1 304 Not Modified");
  16. header("Content-Type: text/html"); // This content-type is always returned for a HTTP 304 response
  17. header("Comment: Have fresh results");
  18. exit;
  19. }
  20. }
  21. else { // No if-last-modified header sent
  22. header("Content-Type: {$content_type}");
  23. header("Last-modified: " . gmdate("D, d M Y H:i:s", (filemtime(__FILE__)) ) . " GMT" );
  24. header("Comment: No if-last-modified header sent");
  25. }
  26. ?>