Linux 拨号vps windows公众号手机端

PHP中response.setheader怎么使用

lewis 6年前 (2019-03-24) 阅读数 10 #程序编程
文章标签 response.setheader

在PHP中,可以使用header()函数来设置响应头。

语法如下:

header(string $header, bool $replace = true, int $http_response_code = 0): void

其中,$header参数是要设置的响应头的字符串,格式为“HeaderName: HeaderValue”,例如:Content-Type: text/html

$replace参数可选,默认为true,表示替换之前设置的相同响应头。如果设置为false,则会追加相同的响应头。

$http_response_code参数可选,用于设置响应状态码。

示例:

header('Content-Type: text/html');
header('Location: http://example.com');
header('HTTP/1.1 404 Not Found');

注意:header()函数必须在任何实际的输出之前调用,否则会报错。

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门