title: Detecting if content was sent prior to a line in a php file in codeigniter
body: <p>I'm trying to change the way the error files from <code>system/application/errors</code> work by logging the errors and showing a 404 page instead. However, sometimes the error occurs in the middle of a page and I need to display only the error page.</p>
  
  <p>I've tried to check if the headers are sent and cleaning the output buffer but it didn't work.
  Any suggestions?</p>
  
  <p><strong>Update:</strong> My question seems to confuse people so I'll clarify. My intention is to show a custom 500 page in the event that an error occurs some time after a part of content was sent and log the conditions in which the error occurred so that a user won't see an ugly page and a hacker won't see leaks. The main problem lies in removing the content before the error.</p>
  
  <p>Strategies that didn't work so far:</p>
  
  <ul>
  <li>checking using <code>ob_end_clean</code></li>
  <li><code>$CI = &amp; get_instance(); $CI-&gt;output-&gt;set_output('only the 500 message');</code></li>
  <li>adding an <code>_output($data)</code> function to the controller and echo-ing only the 500 message if a certain pattern found in the <code>system/application/errors/*.php</code> files is found</li>
  </ul>
  
  <p>Any help is much appreciated.</p>