gpt4 book ai didi

php - PHP 中的 header 会覆盖 HTTP 响应代码

转载 作者:搜寻专家 更新时间:2023-10-31 20:39:48 25 4
gpt4 key购买 nike

在 Apache 级别设置规则,发现 php 中的 header('Location: filename.php') 覆盖了响应代码。看看下面的代码:-

<?php
header('HTTP/1.1 308 Permanent Redirect'); //or Try for 4xx/5xx Code
header('Location: http://hello.php');
?>

预期结果

  • HTTP/1.1 308 永久重定向
  • 主机:localhost:8000
  • 位置:hello.php
  • 连接:关闭
  • X-Powered-By:PHP/5.5.6

实际结果

  • HTTP/1.1 302 Found
  • 主机:localhost:8000
  • 位置:hello.php
  • 连接:关闭
  • X-Powered-By:PHP/5.5.6

Apache 级别有问题还是 PHP 有问题?

更新:ScreenShot

最佳答案

根据 the function documentation page这是 PHP 在发送 Location header 时所需的行为。

编辑:抱歉,误读了您的消息。如果您发送不同于 3xx 的代码,它将覆盖响应代码,因此它应该与 308 一起使用。您确定没有发回其他 HTTP 代码吗?您的客户端是否尝试检索新资源并且您看到 302 作为最终结果?

最终编辑:你试过了吗

header('Location: /some/page.php', TRUE, 308);

关于php - PHP 中的 header 会覆盖 HTTP 响应代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25379247/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com