views:

51

answers:

4

If the ID (ie user) does not exist I send header("Status: 404 Not Found"); to the browser but PHP sends rest of the page too. Then I made it to send nothing but then it showed a blank white page. I want it to show the default error page. How I'll let it to do it?

+1  A: 
header("Status: 404 Not Found");
readfile ($_SERVER['DOCUMENT_ROOT']."/404.html");
exit;

? or you need universal solution?

Col. Shrapnel
What do you mean by universal? I want to learn it too.
ilhan
@ilhan i mean without knowing the actual name of the error page file. I dunno the solution though :)
Col. Shrapnel
+2  A: 

Add die; after the header call as well.

+1  A: 

I think that in this case, if you only set the header, you'll get the default error page of your browser and not of your web server. The problem is that the page exists for the webserver. So if you know where your server's error page is stored, read it from there. And make sure that your response is longer than (I think it was) 512 Bytes, otherwise the browser (especially IE) will give you it's very own error page.

K. Ober
+2  A: 

you can set it via htaccess also,

ErrorDocument 500 http://foo.example.com/500.php
ErrorDocument 404 /404.php
ErrorDocument 401 /401.php
ErrorDocument 403 /403.php

depending on http status response

vertazzar