0

I would like to display some addition text on a page if its a result of a 404 Not Found code. I'd like to reuse the rest of page somewhere else.

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

I didnt find anything on the $_SERVER variable page that seemed to indicate the error code result. How can I check the error code status?

SwDevMan81
  • 48,814
  • 22
  • 151
  • 184
  • possible duplicate of [Easy way to test a URL for 404 in PHP?](http://stackoverflow.com/questions/408405/easy-way-to-test-a-url-for-404-in-php) – Jay Blanchard Mar 09 '15 at 17:24
  • @Jay - I'm not hosting this, so I'll have to see if the curl library is setup. Thanks for the link – SwDevMan81 Mar 09 '15 at 17:28

1 Answers1

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";
}
?>
Ian Thompson
  • 187
  • 1
  • 10