background image

注意:Pragma:no-cache 仅当在安全连接中使用时才防止缓存,如果在非安全页中使用,

 

处理方式与 Expires:-1 相同,该页将被缓存,但被标记为立即过期。
http-equiv meta 标记:
在 html 页面中可以用 http-equiv meta 来标记指定的 http 消息头部。老版本的 IE 可能不支持
html meta 标记,所以最好使用 http 消息头部来禁用缓存。
--------------------------------------------------------------------------------
范例三: 

 

让使用者的浏览器出现找不到档案的信息。

网上很多资料这样写:php 的函数 header()可以向浏览器发送 Status 标头,
如 header(”Status: 404 Not Found”)。但实际上浏览器返回的响应却是:

 

复制代码 代码如下:
 
HTTP/1.x 200 OK

Date

: Thu, 03 Aug 2006 07:49:11 GMT

Server: Apache/2.0.55 (Win32) PHP/5.0.5
X-Powered-By: PHP/5.0.5
Status: 404 Not Found
Content-Length: 0
Keep-Alive: timeout=15, max=98
Connection: Keep-Alive
Content-Type: text/html
 
查了一些资料,正确的写法是:
header(”http/1.1 404 Not Found”);
第一部分为 HTTP 协议的版本(HTTP-Version);第二部分为状态代码(Status);第三部分为
原因短语(Reason-Phrase)。
--------------------------------------------------------------------------------
范例四:让使用者下载档案( 

 

隐藏文件的位置 )

html

 

标签 就可以实现普通文件下载。如果为了保密文件,就不能把文件链接告诉别人,

可以用 header 函数实现文件下载。
代码如下:
 
<?php
header("Content-type: application/x-gzip"); 
header("Content-Disposition: attachment; filename=文件名/"); 
header("Content-Description: PHP3 Generated Data"); 
?>
 
范例四:header 函数前输入内容
一般来说在 header 函数前不能输出 html 内容,类似的还有 setcookie()   

和 session 函数,这

些函数需要在输出流中增加消息头部信息。如果在 header()执行之前有

echo

等语句,当后

面遇到 header()

 “

时,就会报出 Warning: Cannot modify header information - headers already 

sent by ….”错误。就是说在这些函数的前面不能有任何文字、空行、回车等,而且最好在