Detecting if content was sent prior to a line in a php file in codeigniter – Education Career Blog

I’m trying to change the way the error files from system/application/errors 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.

I’ve tried to check if the headers are sent and cleaning the output buffer but it didn’t work.
Any suggestions?

Update: 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.

Strategies that didn’t work so far:

  • checking using ob_end_clean
  • $CI = & get_instance(); $CI->output->set_output('only the 500 message');
  • adding an _output($data) function to the controller and echo-ing only the 500 message if a certain pattern found in the system/application/errors/*.php files is found

Any help is much appreciated.

,

Are you looking for custom 404 error pages for codeigniter?

http://maestric.com/doc/php/codeigniter_404

,

Do you mean changing the default way that CI errors are handled?

http://codeigniter.com/user_guide/general/errors.html

http://www.askaboutphp.com/172/codeigniter-handling-errors.html

Check these two guides out the check out how to handle codeigniter and PHP errors.

Turn on error logging to text file or something, and then turn off all php errors (this is set in index.php) with

error_reporting(E_ERROR);

you should change from E_ALL to E_ERROR to show only messages for fatal run time problems. This will hide all php errors except those that will halt your script execution.

,

On this page scroll down to May 27 2008.
http://php.net/manual/en/function.header.php

If headers have not been sent, it does a
header(‘Location: ‘.$url);
Otherwise it uses some JavaScript to redirect. If JavaScript is disabled it uses a meta tag.

Leave a Comment