homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

PHP header('HTTP/1.0 404 Not Found');
php, header

 5:08 am on Jan 11, 2008 (gmt 0)

I'm just trying to test to see if my header 404 is working in PHP and I have this:

header('HTTP/1.0 404 Not Found');

But when I go to that page, nothing comes up. Is this something I have to explicitly set in Apache? I just want to be able to show a 404.




 5:33 am on Jan 11, 2008 (gmt 0)

It seems to show up for IE but not Firefox... hmmm...


 5:57 am on Jan 11, 2008 (gmt 0)

See if this thread helps ...


 1:55 pm on Jan 11, 2008 (gmt 0)

Well, I tried using the include as per the instructions in the thread you suggested but the 404 still doesn't show up in Firefox. I even tried it on a separate website that I have and it still isn't showing up. I think I might try just redirecting to an actual page that loads instead of throwing a 404. I'm still curious as to why it's not displaying in Firefox though... it seems rather odd. Thanks for the help.


 6:56 pm on Jan 11, 2008 (gmt 0)

Have you got liveheaders for firefox? If so then check what the response from the page you are calling is.

In apache you should have something like -

ErrorDocument 404 /some_dir/my_error_page.php

So that when you go to example.com/doesnt_exist/bla_bla.not
apache redirects that request through to /some_dir/my_error_page.php

You may find that if you have used the full address for the apache ErrorDocument then you will get a 302 status, as http//something (: removed so there isnt a link...is there any way to stop that?) will result in an external redirect and a 302 header, then it gets to that page and has a 404 header thrown at it. Would be very confusing.

So check the headers returned by your 404 page then it may be an apache set up issue, as the php looks fine.


 7:39 pm on Jan 11, 2008 (gmt 0)

Firefox has no built-in default 404 display, so if your PHP script sends no HTML output in addition to the 404 header, nothing will be displayed by the browser.

Internet Explorer on the other hand uses a default informative 404 page if there is no HTML content returned along with the 404 header.

Apache's 404 configuration only applies to plain old .html files that haven't been handled by a filter (e.g. PHP).


 10:48 pm on Jan 11, 2008 (gmt 0)

But you can use the Apache error_docs if you have an Alias setup or at least know the path to the resource. Set up an Alias [httpd.apache.org] to the error_docs directory and then you can use them on a 404 by calling a url_not_found function. Something along these lines ...
function url_not_found() 
header('HTTP/1.x 404 Not Found');
include realpath($_SERVER['DOCUMENT_ROOT'] . '/../error_docs/not_found.html');

Don't forget to make the error_docs available to PHP parsing if there is a base directory restriction [php.net] in place.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved