views:

39

answers:

3

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.

A: 

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.

RandomBits
i think you should read the question again.
altvali
+1  A: 

Are you looking for custom 404 error pages for codeigniter?

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

Kieran Andrews
sorry but i couldn't find anything there that could help me. I want to destroy the output that was sent before an error occured and show a custom 404 or as CodeInChaos suggested a 500 page. $CI = $CI->output->set_output('my custom 500 response'); exit; doesn't work
altvali
So you actually mean error handling?
Kieran Andrews
+1  A: 

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.

Kieran Andrews
Thank you again for your help and your patience. Changing error handling is helpful in a way but what will happen if someone manages to produce an error somewhere in the middle of a view? Some contents will be sent and the part containing the error won't be sent and then some more content will be sent, resulting in an awkward page. Here's what i want to do instead: remove all content sent prior to the error, show my custom 500 response and exit.
altvali
How about using a redirect on the error message?
Kieran Andrews