PHP header() 函数用于向 HTTP 响应发送标头,并在发送页面内容之前使用。它允许设置响应的内容类型、HTTP 响应代码等参数,并可替换之前发送的同名标头。具体用法包括:设置内容类型和 HTTP 响应代码:header("Content-Type: text/html"); header("HTTP/1.1 404 Not Found");设置多个标头:header("Content-Type: text/html"); header("Cache-Control: no-cache
PHP header() 函数的用法
PHP header() 函数用于向 HTTP 响应中发送一个或多个标头。它在发送页面内容之前使用,可以用来控制浏览器或其他客户端如何处理响应。
用法语法
header(string $header, bool $replace = true, int $http_response_code = null)
参数
立即学习“PHP免费学习笔记(深入)”;
用法示例
设置响应的内容类型和 HTTP 响应代码:
header("Content-Type: text/html"); header("HTTP/1.1 404 Not Found");
设置多个标头:
header("Content-Type: text/html"); header("Cache-Control: no-cache, no-store, must-revalidate");
替换之前发送的同名标头:
header("Content-Type: image/jpeg", false);
注意
以上就是php的header函数怎么用的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号