标头 (header) 是服务器以 http 协义传 html 资料到浏览器前所送出的字串,在标头
与 html 文件之间尚需空一行分隔。有关 http 的详细说明,可以参 rfc 2068 官方文件
(http://www.w3.org/protocols/rfc2068/rfc2068)。在 php 中送回 html 资料前,需先
传完所有的标头。
注意: 传统的标头一定包含下面三种标头之一,并只能出现一次。
content-type: xxxx/yyyy
location: xxxx:yyyy/zzzz
status: nnn xxxxxx
在新的多型标头规格 (multipart mime) 方可以出现二次以上。
使用范例
范例一: 本例使浏览器重定向到 php 的官方网站。
header("location: http://www.php.net");
exit;
>?
范例二: 要使用者每次都能得到最新的资料,而不是 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");
>?
范例三: 让使用者的浏览器出现找不到档案的信息。
header("status: 404 not found");
>?
范例四:让使用者下载档案。
header("content-type: application/x-gzip");
header("content-disposition: attachment; filename=文件名");
header("content-description: php3 generated data");
>?
