如何在PHP中设置自定义标头 [英] How to set custom headers in PHP
本文介绍了如何在PHP中设置自定义标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
JAVA开发人员在标头中发送数据。我这样说吧
JAVA developer send me data in headers. I take it this way
$_SESSION["HTTP_COUNTRYNAME"];
如何使用标题回复?它试过 header(countryname:USA);
但是php function headers_list
没有显示它。
How to make response back with headers? It tried header("countryname: USA");
but php function headers_list
doesn't show it.
推荐答案
header('countryname: USA');
print_r(headers_list());
Array ( [0] => X-Powered-By: PHP/5.3.0 [1] => countryname: USA )
...对我有用。
你确定之前没有输出任何东西吗?开始打印文本后,无法设置标题。使用 headers_sent()
查看标题是否已发送(即,如果您已输出内容)。
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).
这篇关于如何在PHP中设置自定义标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文