【问题标题】:Determine if a page is a result of being redirected from a 404 Not Found code确定页面是否是从 404 Not Found 代码重定向的结果
【发布时间】:2015-05-10 23:10:48
【问题描述】:

如果是 404 Not Found 代码的结果,我想在页面上显示一些附加文本。我想在其他地方重用页面的其余部分。

<div>
   <?php
      if(page_is_404_redirect)
      {
         <div>Oh no, I couldn't find what you were looking for.</div>
      }  
   >?
   ...
</div>

我在$_SERVER variable page 上没有找到任何似乎表明错误代码结果的内容。如何查看错误码状态?

【问题讨论】:

标签: php redirect http-status-code-404 system-variable


【解决方案1】:
<?php
$previous = $_SERVER['HTTP_REFERER'];
$headers = @get_headers($previous);
if($headers[0] == 'HTTP/1.1 404 Not Found')
{
echo "Previous page was 404 error";
}
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-26
    • 1970-01-01
    • 2016-08-31
    • 2017-06-23
    • 1970-01-01
    • 1970-01-01
    • 2019-12-16
    • 2018-10-26
    相关资源
    最近更新 更多