Re: Re: [PATCH] Allow unsetting headers previously set by header()
| From: | Sam Barrow | Date: | Sun, 30 Mar 2008 21:05:51 +0000 |
| Subject: | Re: Re: [PATCH] Allow unsetting headers previously set by header() | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-36692@lists.php.net to get a copy of this message | ||
On Sun, 2008-03-30 at 16:05 -0400, Edward Z. Yang wrote:
> Christian Schmidt wrote:
> > What do you think of the general idea of being able to unset
> headers?
> > And what do you think of my patch?
>
> If you need this kind of flexibility, I recommend you make an
> HttpHeaders class which manages these things and then sends them when
> necessary.
>
That's what I do. All you need is some simple functions:
$headers = array();
addHeader($name, $value) {
global $headers;
$headers[$name] = $value;
return true;
}
deleteHeader($name) {
global $headers;
if (array_key_exists($name, $headers)) {
unset($headers[$name]);
}
return true;
}
sendHeaders() {
global $headers;
foreach ($headers as $name => $value) {
header($name . ': ' . $value);
}
return true;
}