How to set custom headers in PHP

2020-06-08 18:36发布

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

$_SESSION["HTTP_COUNTRYNAME"];

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

1条回答
Luminary・发光体
2楼-- · 2020-06-08 18:57
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).

查看更多
登录 后发表回答