Heim  >  Artikel  >  Backend-Entwicklung  >  header函式的使用_PHP教程

header函式的使用_PHP教程

WBOY
WBOYOriginal
2016-07-13 17:27:21805Durchsuche

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

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/531887.htmlTechArticle标头 (header) 是服务器以 HTTP 协义传 HTML 资料到浏览器前所送出的字串,在标头 与 HTML 文件之间尚需空一行分隔。有关 HTTP 的详细说明,可...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn