note 77846 added to function.header
| From: | predefining at gmail dot com | Date: | Sat, 15 Sep 2007 15:39:26 +0000 |
| Subject: | note 77846 added to function.header | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130514@lists.php.net to get a copy of this message | ||
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
----
Server IP: 217.160.72.57
Probable Submitter: 217.85.218.221
----
Manual Page -- http://www.php.net/manual/en/function.header.php
Edit -- https://master.php.net/note/edit/77846
Del: integrated -- https://master.php.net/note/delete/77846/integrated
Del: useless -- https://master.php.net/note/delete/77846/useless
Del: bad code -- https://master.php.net/note/delete/77846/bad+code
Del: spam -- https://master.php.net/note/delete/77846/spam
Del: non-english -- https://master.php.net/note/delete/77846/non-english
Del: in docs -- https://master.php.net/note/delete/77846/in+docs
Del: other reasons-- https://master.php.net/note/delete/77846
Reject -- https://master.php.net/note/reject/77846
Search -- https://master.php.net/manage/user-notes.php