note 77846 deleted from function.header by danbrown
| From: | danbrown@php.net | Date: | Sun, 07 Dec 2008 18:11:48 +0000 |
| Subject: | note 77846 deleted from function.header by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-147809@lists.php.net to get a copy of this message | ||
Note Submitter: predefining at gmail dot com
----
I couldn't find an example how to send a status code without the need of resolving the
description (e.g. "Not found"). So I was thinking of an array containing all status codes
and their descriptions but looking them up can slow down the execution of the script - depending on
the array's size. I've looked for an alternative: The solution is to use the third
parameter which can send a status code without the need to specify its description! header() will
ONLY send the status code if the first parameter is not (!) empty.
function sendStatusCode($statusCode)
{
header(' ', true, $statusCode);
}
sendStatusCode(404);
This will only work if you're using PHP 4.3.0 or higher. Otherwise you rely on one of the
following methods:
header('Status: 404 Not Found');
header('HTTP/1.0 404 Not Found');
Best regards,
Tim