php中header()作用

来源:百度知道 编辑:UC知道 时间:2024/06/30 06:44:57
我看的函数手册,还是不大懂,希望好人指点一下,先谢过了

1、函数描述:
header() 函数向客户端发送原始的 HTTP 报头。
2、函数语法:
header(string,replace,http_response_code)

3、函数参数:
①string:必需。规定要发送的报头字符串;
②replace :可选。指示该报头是否替换之前的报头,或添加第二个报头。默认是 true(替换)。false(允许相同类型的多个报头);
③http_response_code:可选。把 HTTP 响应代码强制为指定的值。
4、函数举例:
<?php
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
?>
<html>
<body>

header() 函数向客户端发送原始的 HTTP 报头。

例子 1

//页面跳转
header('Location: http://www.example.com/');


例子 2

//提示用户保存一个生成的 PDF 文件(Content-Disposition 报头用于提供一个推荐的文件名,并强制浏览器显示保存对话框)
header("Content-type:application/pdf");
// 文件将被称为 downloaded.pdf
header("Content-Dis