tags:

views:

38

answers:

2

Is there a way to have a php script return a specific http status code rather than relying on apache to do it?

+6  A: 
header("HTTP/1.0 404 Not Found");

http://php.net/header

Frank Farmer
Boo you just beat me :P +1
GWW
That's correct except I put HTTP/1.1 instead of 1.0. HTTP 1.0 is a dinosaur; it doesn't allow many features of the modern web. Granted, PHP would probably convert it to 1.1 anyway...
thomasrutter
Actually.... You would check which HTTP version was requested of course, and respond in kind :P
Wrikken
Usually I use this with a javascript auto refresh and the status code of 204 to tell the browser that there is no content. This way, the page will not refresh if there is nothing to update. (or refresh if there is a change)Only problem is on IE it will generate that horrible clicking sound every time the page is called.
iWantSimpleLife
+1  A: 

You can set header values manually with php, for example:

<?php
header("HTTP/1.0 404 Not Found");
?>
GWW