I have a web-server and I would like to have the HTTP status code 418 'I'm a teapot' under some conditions, I am sure I would use an if statement, I just can't seem to get it to trip, any help?
Asked
Active
Viewed 8,365 times
8
-
What do you mean "Under some conditions?" – Feb 12 '13 at 01:06
-
2Like the first time a user visits on the first of April. – gudenau Feb 12 '13 at 01:07
-
Start here, http://php.net/manual/en/control-structures.if.php – Lawrence Cherone Feb 12 '13 at 01:08
-
I know how to use if, while, d while, ect, I just need to get the code to return... – gudenau Feb 12 '13 at 01:10
-
Use the `header()` function, beware of [error cases](http://stackoverflow.com/questions/8028957/headers-already-sent-by-php), and note that you can't usually show a page along (built-in browser replacements). – mario Feb 12 '13 at 01:11
-
I use header("HTTP/1.1 404 Not Found") to try a common code, but it does nothing, first line after php – gudenau Feb 12 '13 at 01:17
1 Answers
32
<?php
header("HTTP/1.1 418 I'm a teapot");
?>
<html>
<h1>418 I'm a teapot</h1><br>
<p>The HTCPCP Server is a teapot. The responding entity MAY be short and stout.</p>
</html>
Will result in:
418 I'm a teapot
The HTCPCP Server is a teapot. The responding entity MAY be short and stout.

James Billingham
- 760
- 8
- 32