Home > php教程 > php手册 > body text

PHP header 函数教程

WBOY
Release: 2016-06-13 11:16:48
Original
854 people have browsed it

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)
Copy after login
Copy after login
Copy after login
		Parameter
Copy after login
Description
string 必需的。指定的标题字符串发送
replace 任择。指示是否标题应取代以前或添加第二个标题。预设值是true (将取代) 。假(允许多个标题同一类型)
http_response_code 任择。部队的HTTP响应代码到指定的值(可在PHP 4.3和更高)
Copy after login
Copy after login

提示和说明 注:自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'");
Copy after login
// The PDF source is in original.pdfreadfile("original.pdf");
Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!