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!
How to know when output has already started
Moderator: General Moderators
-
yanglei1979
- Forum Commoner
- Posts: 38
- Joined: Sat Aug 25, 2007 10:21 pm
Re: How to know when output has already started
print_r($_POST);
Re: How to know when output has already started
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!
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!
Last edited by sideral on Sun Jan 13, 2008 11:12 pm, edited 1 time in total.
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: How to know when output has already started
This is actually the function I was looking for! Thank you!