Php 如何制作FPDF';s生成的pdf不可缓存?

Php 如何制作FPDF';s生成的pdf不可缓存?,php,continuous-integration,fpdf,cache-control,Php,Continuous Integration,Fpdf,Cache Control,我正在检查一个用原始php编写的应用程序,没有任何框架。在一个模块中,有使用FPDF生成的报告,并且工作正常,只是PDF被缓存了。生成例程的原始调用是 <a href="tr_inci_print.php" target="_new">Print</a> 与 这解决了Chrome和IE中的问题,但在FireFox 4中没有解决。您只需设置一个标题即可实现这一点,只需将以下行添加到tr_inci_print.php: header("Cache-Control: no-c

我正在检查一个用原始php编写的应用程序,没有任何框架。在一个模块中,有使用FPDF生成的报告,并且工作正常,只是PDF被缓存了。生成例程的原始调用是

<a href="tr_inci_print.php" target="_new">Print</a>


这解决了Chrome和IE中的问题,但在FireFox 4中没有解决。

您只需设置一个标题即可实现这一点,只需将以下行添加到
tr_inci_print.php

header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");   // any date in the past
编辑:请确保在调用
output()

之前添加这几行,然后重试:

<a href="tr_inci_print.php?t=<?php echo time(); ?>" target="_new">Print</a>

编辑:添加Javascript以确保pdf是新鲜的,即使不重新加载主页:

<a href="tr_inci_print.php?t=<?php echo time(); ?>"
   onclick="document.location.href='tr_inci_print.php?t='+new Date().getTime(); return false;" >
  Print
</a>


谢谢oezi,但没用。我在output()之前插入了代码,但没有效果,仍然得到了缓存的版本。from output()函数:header('Cache-Control:private,max age=0,必须重新验证');所以它重写了指令。我会尝试自己输出。谢谢塔康。问题是带有链接的页面没有重新加载,因此href在此之前不会更改。可能有一些js可以产生这种效果。这没关系,这是我的想法,考虑到pdf应该在另一个窗口中打开,所以只需轻轻一触,它就是我想要的。谢谢
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");   // any date in the past
<a href="tr_inci_print.php?t=<?php echo time(); ?>" target="_new">Print</a>
<a href="tr_inci_print.php?t=<?php echo time(); ?>"
   onclick="document.location.href='tr_inci_print.php?t='+new Date().getTime(); return false;" >
  Print
</a>