dongmeiwei0226 2012-10-20 19:02
浏览 84
已采纳

为什么HTTP响应代码在PHP $ _SERVER变量中不可用?

Why is the HTTP response code (or the first line of the HTTP response header) not available in the PHP $_SERVER variable array?

Is it a limitation on the way server technology works? A limitation with PHP? With the HTTP protocol? Or maybe I'd be completely NUTS to ever want the HTTP response code? ;)

In my case, I'm working with Apache2.

Just curious.

EDIT 1: I'm inquiring about the equivalent of %>s (the status of the LAST request) used by Apache's LogFormat directive before the server response is sent.

EDIT 2: The answers make perfect sense, but the question remains, why can't I get my server's internal working response code? If I set an ErrorDocument 403 /index.php, I can access the response code with $_SERVER['REDIRECT_STATUS']. Isn't there an easier way? I'm guessing not. I still learned a lot from your answers, however. It makes sense.

There's also apache_response_headers(), but still no love for the working response code/first line.

  • 写回答

3条回答 默认 最新

  • doulu1867 2012-10-20 19:04
    关注

    Because the HTTP response is something that is sent to the client, and you can change it within your PHP using the header function. It's not something that is automatic within your PHP and would be handled by the server (ie apache) before it would be given over to PHP.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog