Table of Contents

pdf HTTP headers

// HTTP 1.1
// max-age=6 : this page is stale after 6 seconds, and should be reloaded
// private : output is intended for a single user, and not to be stored in a shared cache
header("Cache-Control: max-age=6, private");
 
// HTTP 1.0 (Cache-Control may be ignored by 1.0, and Pragma: no-cache would be obeyed)
// we could say almost anything here, it is just to avoid Pragma: no-cache by default in php,
// since php doesn't provide another way to modify the Pragma directive
header("Pragma: hack");
 
// set expiration time and last modified; however, the client may ignore this and cache
// or update the output by another method
$time = time();
header("Expires: " . gmdate('D, d M Y H:i:s', $time + 6) . " GMT");
header("Last-Modified: " . gmdate('D, d M Y H:i:s', $time) . " GMT");
 
header("Content-Type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=\"$name\"");
header("Content-Transfer-Encoding: binary");

Making IE Accept File Downloads

Over SSL (https:), you may get a message in IE of “The file could not be written to the cache”. This can be resolved by the following:

  1. make sure to uncheck Tools → Internet Options → Advanced → Do not save encrypted pages to disk
  2. use the following (notice it is before session_start()):
    if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
        session_cache_limiter("public");
    }
    session_start();

See Also