0

I have read the other thread on this specific topic but I believe that there is white space being generated by ob_end_flush().

  1. In my code if I precede my call to ob_end_flush() with a header() the header works
  2. If remove the leading header() and put it after the call to ob_end_flush() then the header fails to execute.
  3. In the latter case, I inspect the page (Control-U in FireFox) and see one blank line

Here is the code with BOTH header calls. again, the leading header works but if I remove the 1st header the header subsequent to ob_end_flush() fails.

header('location:administrative page.php');  //-- return

ob_end_flush();

header('location:administrative page.php');  //-- return

The problem cannot be related to any undetected leading or trailing white space above or below my "PROBLEM AREA" code since the 1st header works.

Any ideas? ======================================== addendum 2/12/2015 Thanks to both replies... I need to pay more attention to my error logs in challenging times ...

The "surprise" to me is that evidently ob_end_flush() initiates a header send and thus "my" subsequent header construct is blocked. Line 101 is: ob_end_flush(); Line 105 is: header('location:administrative page.php');

20150212T083215: www.summersessiondevelopment.com/report.php 

PHP Warning: Cannot modify header information - headers already sent by (output started at /hermes/waloraweb026/b1614/moo.aassdevelopmentcom/report.php:101) in /hermes/waloraweb026/b1614/moo.aassdevelopmentcom/report.php on line 105

so, my task is to now find the definitive way to flush my fputcsv() buffer before I close the file with fclose($fp) without using ob_end_flush();

I used a brute force method trying to find a way to flush the buffer so I will check to see if removing ob_end_flush() and only using:

ob_flush();
flush();
fclose($fp);

does the trick.

Again THANKS guys!

  • possible duplicate of [How to fix "Headers already sent" error in PHP](http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) – Jon Surrell Feb 10 '15 at 17:06

1 Answers1

1

ob_end_flush outputs the buffer. You cannot have any output before a call to header.

If you need to store the results to display later, use ob_get_flush instead.

See the documentation and consider checking your PHP error logs.

Mr. Llama
  • 20,202
  • 2
  • 62
  • 115
  • John, thank you .... but I am a bit confused on what is considered "output". the following line is executed "n" times before I get down to the flush constructs ..... fputcsv($fp, $fields); ..... the header conundrum with respect to ob_end_flush() doesn't seem to mind the fputcav() "outputs". I do) use flush() and fcose() but they don't always seem to properly spill the buffer. below current code (the header fails) - but the only construct that always flushs the buffer. ob_end_flush(); ob_flush(); flush(); fclose($fp); header('location:administrative page.php'); //-- return – Gerry Williams Feb 11 '15 at 22:26
  • @GerryWilliams - I think you replied to the wrong comment. As far as the `header` function is concerned, "output" is any text that will be sent to the browser. Error messages, warnings, HTML, whitespace, anything. If you have any of that before a `header` call, it will fail. – Mr. Llama Feb 11 '15 at 22:45