复制代码
强制用户每次访问这个页面时获取最新资料,而不是使用存在客户端的缓存。
复制代码
输出状态值到浏览器,主要用于访问权限控制
复制代码
比如要限制一个用户不能访问该页,则可设置状态为404,如下所示,这样浏览器就显示为即该页不存在
复制代码
注意: 传统的标头一定包含下面三种标头之一,并只能出现一次。 content-type: xxxx/yyyy location: xxxx:yyyy/zzzz status: nnn xxxxxx 在新的多型标头规格 (multipart mime) 方可以出现二次以上。以上就是有关php header头信息的内容介绍,更多内容可以参考:php 文件头部(header)信息详解 。
举一些具体的例子。
例1: 本例使浏览器重定向到 php 的官方网站。
header(location: http://www.php.net); exit;
复制代码
例2: 要使用者每次都能得到最新的资料,而不是 proxy 或 cache 中的资料,可以使用下列的标头
header(expires: mon, 26 jul 1997 05:00:00 gmt);header(last-modified: . gmdate(d, d m y h:i:s) . gmt); header(cache-control: no-cache, must-revalidate);header(pragma: no-cache);
复制代码
例3: 让使用者的浏览器出现找不到档案的信息。
header(status: 404 not found);
复制代码
例4:让使用者下载档案。
header(content-type: application/x-gzip);header(content-disposition: attachment; filename=文件名);header(content-description: php3 generated data);
复制代码
说明:不管页面有多少header,它会执行最后一个,不过是有条件的,例如:
header('location:http://bbs.it-home.org');header('location:http://www.g.cn');header('location:http://www.baidu.com');//跳到百度header('location:http://bbs.it-home.org');echo '程序员之家';header('location:http://www.g.cn');header('location:http://www.baidu.com');//跳到google
复制代码