好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

php的header的用法详解

php header用于向客户端发送原始的HTTP报头,该函数的语法是“header(string,replace,http_response_code)”,其中参数string表示要发送的报头字符串。

PHP header() 函数

定义和用法

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

认识到一点很重要,即必须在任何实际的输出被发送之前调用 header() 函数(在 PHP 4 以及更高的版本中,您可以使用输出缓存来解决此问题):

<html>
<?php
// 结果出错
// 在调用 header() 之前已存在输出
header('Location: http://HdhCmsTestexample测试数据/');
?>
<?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>
...
...

提示用户保存一个生成的 PDF 文件(Content-Disposition 报头用于提供一个推荐的文件名,并强制浏览器显示保存对话框):

<?php
header("Content-type:application/pdf");
// 文件将被称为 downloaded.pdf
header("Content-Disposition:attachment;filename='downloaded.pdf'");
// PDF 源在 original.pdf 中
readfile("original.pdf");
?>
<html>
<body>
...
...

注释:微软 IE 5.5 存在一个阻止以上机制的 bug。通过升级为 Service Pack 2 或更高的版本,可以解决该 bug。

更多相关知识,请访问PHP中文网!

以上就是php的header的用法详解的详细内容!

查看更多关于php的header的用法详解的详细内容...

  阅读:37次