6

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

0

2 Answers 2

11
header("HTTP/1.0 404 Not Found");

http://php.net/header

Sign up to request clarification or add additional context in comments.

3 Comments

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...
Actually.... You would check which HTTP version was requested of course, and respond in kind :P
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.
5

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

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.