Page 1 of 1

How to know when output has already started

Posted: Sun Jan 13, 2008 10:30 pm
by sideral
Hi all! I'm new to this forum and I will be happy to help someone, but this time I'm the one in need of help!

My problem is: Is there a way to know if a script has already sent data to the browser, even if (an specially if) output buffering is not enabled?

For example, in the simple page:

<html>
<!--insert some html here-->

<?php // Is there a way to know here if some of the previous html has already been sent to the browser? ?>

</html>

Thank you very much!

Re: How to know when output has already started

Posted: Sun Jan 13, 2008 10:42 pm
by yanglei1979
print_r($_POST);

Re: How to know when output has already started

Posted: Sun Jan 13, 2008 11:11 pm
by sideral
Thank you for your response, but unfortunately this doesn't actually solves the problem.
Maybe I didn't explan myself correctly, so i'd like to clarify a bit

I'm not referring to detect when the browser sends data to php, but conversely, detect when php has sent data to the browser.

I am working on an application that easily could make, say, 10 database querys before processing any html. However the number of preprocessing varies greatly from page to page. In case any of those pages finds an error during a query (or in any other part), I want to be able to catch it and redirect the page to an error page, but http redirection doesn't work when the script has already started its output. Normally, this could be done by buffering the output and if something wrong happens, clean the buffer and make the redirection. However, in this particular case, output buffering is optional, so I can't rely on that.

My idea is, then, to use javascript or html redirection in case output has been sent. If something goes wrong, the script would detect if data has been sent. If it wasn't, then use http redirection, but if it was, then add a little script into the html to redirect.

Well, now.. I don't know a way to detect this in php, and, as I said, output buffering is not an option.

Thank you again!

Re: How to know when output has already started

Posted: Sun Jan 13, 2008 11:11 pm
by alex.barylski

Re: How to know when output has already started

Posted: Sun Jan 13, 2008 11:14 pm
by sideral
This is actually the function I was looking for! Thank you!