Is there a way to have a php script return a specific http status code rather than relying on apache to do it?
Asked
Active
Viewed 5,249 times
2 Answers
11
header("HTTP/1.0 404 Not Found");

Frank Farmer
- 38,246
- 12
- 71
- 89
-
1That'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 Aug 04 '10 at 02:11
-
3Actually.... You would check which HTTP version was requested of course, and respond in kind :P – Wrikken Aug 04 '10 at 02:22
-
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 Aug 04 '10 at 04:45
5
You can set header values manually with php, for example:
<?php
header("HTTP/1.0 404 Not Found");
?>

GWW
- 43,129
- 11
- 115
- 108