SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: Cancel headers
-
May 22, 2009, 11:58 #1
- Join Date
- Mar 2005
- Location
- Madison, WI
- Posts
- 165
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Cancel headers
As we all know, the header function is useful for setting the page headers. You'll often see people new to PHP asking questions like, "is there some to way to clear the headers already sent?" They ask because they usually want to set cookies / session variables late, after output has occurred, because they lack a basic knowledge of how headers work.
That is not my question. I'm pointing that explicitly to hopefully prevent anyone coming in here with the assumption that that was my question and accordingly making some condescending reply.
My actual question:
Is there some way to clear/cancel the headers before anything has been sent/output? It only makes sense that the headers that are going to be sent are stored internally in some hidden PHP system array or somesuch, so I would think it would be a fairly easy procedure to clear it before the output has happened. Yet I'm having trouble figuring out how, or if any function/method to do so exists.// useless crap about my relationships, philosophy,
// theology, music and programming projects:
my $blog = 'http://gordon-myers.com/';
-
May 22, 2009, 12:06 #2
- Join Date
- Mar 2002
- Location
- Bristol, UK
- Posts
- 2,240
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Well according to the manual, the header() function sends the headers to the user's browser, so I would think that there is no way to stop what has already been sent. This note on the manual page seemed the most relevant to your question:
Note: The HTTP status header line will always be the first sent to the client, regardless of the actual header() call being the first or not. The status may be overridden by calling header() with a new status line at any time unless the HTTP headers have already been sent.
-
May 22, 2009, 12:18 #3
- Join Date
- Mar 2005
- Location
- Madison, WI
- Posts
- 165
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Your reading of the manual is not quite right. The actual sending of data does not take place when you make the header call; it takes place later when you actually send output or at script termination. This is confirmed in the manual entry for the headers_sent function, which returns true/false to indicate whether or not they have been sent yet.
// useless crap about my relationships, philosophy,
// theology, music and programming projects:
my $blog = 'http://gordon-myers.com/';
-
May 30, 2009, 19:34 #4
- Join Date
- Jul 2008
- Posts
- 5,757
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
header_remove() is coming
http://wiki.php.net/doc/scratchpad/upgrade/53
Bookmarks