Maison > php教程 > php手册 > le corps du texte

PHP header 函数教程

WBOY
Libérer: 2016-06-13 11:16:48
original
854 Les gens l'ont consulté

header ( )函数发送一个原始HTTP头到客户端。 header(string,replace,http_response_code)重要的是要看到,标题( )必须在任何所谓的实际产出发送  

PHP header 函数教程

定义和用法
header ( )函数发送一个原始HTTP头到客户端。

重要的是要看到,标题( )必须在任何所谓的实际产出发送(在PHP 4和以后,您可以使用输出缓冲来解决这个问题) :

// This results in an error.
// The output above is before the header() call
header('Location: http://www.example.com/');
?>

语法:

header(string,replace,http_response_code)
Copier après la connexion
Copier après la connexion
Copier après la connexion
		Parameter
Copier après la connexion
Description
string 必需的。指定的标题字符串发送
replace 任择。指示是否标题应取代以前或添加第二个标题。预设值是true (将取代) 。假(允许多个标题同一类型)
http_response_code 任择。部队的HTTP响应代码到指定的值(可在PHP 4.3和更高)
Copier après la connexion
Copier après la connexion

提示和说明 注:自PHP 4.4这一功能可以防止一个以上的标题发送一次。这是一个保护,防止头注入攻击。 范例1 防止页面缓存:

 

// Date in the pastheader("Expires: Mon, 26 Jul 1997 05:00:00 GMT");header("Cache-Control: no-cache");header("Pragma: no-cache");

 

示例2 让用户将提示保存生成的PDF文件(内容处置标题是用来提供建议的文件名,并迫使浏览器来显示保存对话框) :

 

header("Content-type:application/pdf");

// It will be called downloaded.pdfheader("Content-Disposition:attachment;filename='downloaded.pdf'");
Copier après la connexion
// The PDF source is in original.pdfreadfile("original.pdf");
Copier après la connexion

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Recommandations populaires
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!