php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #23228 output function
Submitted: 2003-04-15 15:18 UTC Modified: 2011-01-01 01:30 UTC
Votes:1
Avg. Score:2.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: prof_moriarty at veryfast dot biz Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 4.3.0 OS: Win 98
Private report: No CVE-ID: None
 [2003-04-15 15:18 UTC] prof_moriarty at veryfast dot biz
A feature request.
I've been reading through the manual for 4.3.something, and i can't find a function to do this, so i figured i'd suggest it.

Basically a function that will determine if any data has actually been sent to the browser, and return TRUE or FALSE depending on the result.
This function would check to see if ANY data had been sent to the browser (cookies and headers excluded), including error messages!


I realise there are the "output control functions", however in the case i have, they don't really help me. Partially because i'm not sure if errors are actually buffered or sent straight through ignoring them.

Also there is the $php_errormsg variable, but that's only related to the 'track errors' configuration which defaults to off (meaning it's never going to be on on a host).

Thanx
Jonathan

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-04-22 14:18 UTC] pollita@php.net
headers_sent() will do what you want.

I know you're asking for a function which tells you if NON-header infomation has been sent (as stated in your second paragraph), but the exact way in which headers are buffered needs to be understood.

headers are never sent until content is forced out to the browser.  Therefore headers_sent() will not return TRUE until real content has reached the browser.

If output buffering is on, real content (such as: print "foo!\n"; ) can be in the buffer (but not sent to the browser) without having sent headers (and so headers_sent() will return FALSE).  When that buffer is flushed to the browser however, the headers are flushed as well (making that function return TRUE).

If output buffering is not on, individual headers can be sent, but headers_sent() will not yet return TRUE because header content is psuedo-buffered until content is sent.  Again, once content is output the headers are flushed and headers_sent() will begin returning TRUE.
 [2003-06-02 15:34 UTC] prof_moriarty at veryfast dot biz
Let's see if i'm getting the gist of this:
I send data to the browser, followed by a header, and headers_sent will return true.
Or something like that.

But what i want to be able to do is:

Check to see if any data has been sent to the browser BEFORE sending headers...
because the headers that I want to send are based on the content of the page.

i.e.:
Script to generate a .png image. Most browsers will only show a .png when the thing has the correct headers 
   Header("Content-type: image/png");

But let's say something goes wrong with the script, and an error is reported.
If i then proceed to tell the browser the thing is an image, i get a big white screen (because the result is actually a fairly messed up image, with text in it (which can be viewed by looking at the page-source))...

so my function would do something like:

if(proposed_function()){
   Header("Content-type: image/png"); //no errors
} else {
   //error, so tell the browser we're playing with text, not an image
   Header("Content-type: HTML");
}


I hope that better explains it... And if such an ability does excist (without having to use output control), then i'm sorry for wasting your time... :)
 [2011-01-01 01:30 UTC] jani@php.net
-Status: Open +Status: Bogus -Package: Feature/Change Request +Package: *General Issues
 [2011-01-01 01:30 UTC] jani@php.net
Wasting time.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 21:01:32 2024 UTC