欢迎光临
我们一直在努力

header 函式的使用-PHP教程,PHP应用

建站超值云服务器,限时71元/月

标头 (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");

>?

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » header 函式的使用-PHP教程,PHP应用
分享到: 更多 (0)

相关推荐

  • 暂无文章