如何在 PHP 中设置自定义标头

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7299977/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:25:40  来源:igfitidea点击:

How to set custom headers in PHP

phphttp-headers

提问by Dimash

JAVA developer send me data in headers. I take it this way

JAVA 开发人员在标题中向我发送数据。我这样理解

$_SESSION["HTTP_COUNTRYNAME"];

How to make response back with headers? It tried header("countryname: USA");but php function headers_listdoesn't show it.

如何使用标头回复回复?它试过了,header("countryname: USA");但 phpfunction headers_list没有显示出来。

回答by Andreas

header('countryname: USA');
print_r(headers_list());

Array ( [0] => X-Powered-By: PHP/5.3.0 [1] => countryname: USA ) 

...works for me.

...对我有用。

Are you sure you haven't output anything before it? You cannot set headers after you've started printing text. Use headers_sent()to see if the headers have already been sent (that is, if you've already output something).

你确定你之前没有输出任何东西吗?开始打印文本后,您无法设置标题。使用headers_sent(),看是否标头已经发送(也就是说,如果你已经输出的东西)。