首页 > php函数 > PHP header 函数教程

PHP header 函数教程

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

PHP header 函数教程

定义和用法

header()函数发送一个原始HTTP头到客户端。 

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

<?php
// 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)

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

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

header("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.pdf

header("Content-Disposition:attachment;filename='downloaded.pdf'");

// The PDF source is in original.pdf

readfile("original.pdf");


本文地址:http://www.phprm.com/function/0f03f61bdc1a75bc79f33eea54c153bf.html

转载随意,但请附上文章地址:-)

标签:none

发表留言