duanhe6718 2014-01-24 13:46
浏览 49
已采纳

读取先前请求的标题

I came across a question which raised me some sort of curiosity. Is it possible to read custom headers sent in a different request?

Using header_list() it's possible to read the headers sent, like the Content-type one. So, in the same request, this code:

<?php

header( 'My Header: My Value' );

print '<pre>'; 

print_r( headers_list() );

Would produce:

Array
(
    [0] => X-Powered-By: PHP/5.4.24
    [1] => My Header: My Value
    [2] => Content-type: text/html
)

But what if I would like to get the My Header header in a different request, to a different URL maybe, after sending a Location header like this?

<?php

header( 'My Header: My Value' );

header( 'Location: test2.php' );

The print_r(), if used in test2.php lists the Content-type and the X-Powered-By, but it doesn't read the My Header header.

  • 写回答

1条回答 默认 最新

  • duanganleng0577 2014-01-24 13:49
    关注

    No, it's not possible to get the header list of a different request. The most obvious question would be: which different request?! There can be thousands of simultaneous "other" requests going on, so "another" request is a bit vague.

    If you need to retain that information for later, store it somewhere, for example in the session.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用lstm来预测股票价格
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上