Forum Moderators: coopster
i have functions which deal effectively with this architecture. but my problem is how do i send a 404 header if say, the file requested through $_REQUEST['cat'] does not exist or even if it does the id requested thru $_REQUEST['subcat'] does not exist in the related tables?
i tested with both header("HTTP/1.0 404 Not Found"); and header("Status: 404 Not Found"); for the purpose, set up a customised 404.php page. yet nothing happens. i mean theres no errors (on my production environment i have switched off error reporting and in my dev environment i dont get any errors either). its all the more frustrating coz all other kind of headers work. i start ob_start at the top of my pages for these kinds of things and yet i dont get what i want.
i know i can create other error pages to take care of these problems, but i want the 404 haeder to work basically.
how do i resolve this issue? any thoughts?
could the problem be happening coz the header is being sent from include files from outside my www directory?
any thoughts anyone?please
The header() code is correct, so it looks like it comes down to code order/structure/conditional value(s).
Justin
this 404 header is indeed conditional...send it if there is nothing.
are other headers being sent even if there is no information found?
Yes actually. since other parts of the headers are created in various included files. the decision whether or not 404 is to be sent occurs in the middle segment.
btw there is not likely to be any conflict between two separate headers going out together. the header to be sent is declared as a config variable available throughout the site and its just that variable which is repeated everywhere.
If you run the header check and you are not getting a 404...
I would guess the problem has to do with the other headers -- I would set them in the includes as you are doing, but not send them until after the decision is made to send a 404 or not. IOW Run your scripts, but do not output any information or send any headers until you know if there is a result or not. Then send them all at once.
If you do this, make sure you do not set another status code after the 404, because it will override the initial status. (If you are redirecting when you send 'not found', I would recommend using an include instead.)
Let us know what you find.
Justin
are other headers being sent even if there is no information found?
Yes actually. since other parts of the headers are created in various included files. the decision whether or not 404 is to be sent occurs in the middle segment.
It is not quite sure what you mean with "other parts of the headers". HTTP headers? HTML page headers?
If you want to state a 404, just send the plain one 404 HTTP header() and nothing else.
The header() stuff would not work at all, if you have output any text before (including any HTML header text), so your decision to send a 404 or not has to be at the very beginning and before of all further page generation.
Regards,
R.
HTTP/1.1 404 Not Found
Date: Tue, 20 Sep 2005 03:21:58 GMT
Server: Apache
X-Powered-By: PHP/4.3.11
Set-Cookie: BKiD=191865409; expires=Thu, 20-Oct-05 03:21:58 GMT; path=/; domain=.deletedthedomainname.com
Connection: close
Content-Type: text/html
as expected its returning HTTP/1.1 404 Not Found, for a cat and subcat which do not exist.
so as jd01 mentioned, i might need to exit(); will try that.
"IOW Run your scripts, but do not output any information..."
I already have ob_start(), is there any other ways this can be achieved?
To answer Romeo's question: they are HTML page headers. theres nothing else i am sending thru the php header();
thank you jd and romeo for all the help. and particularly this Server Header Check tool is very useful