Re: display_errors off and custom error pages

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




I've spent the last couple of hours trying to work this out to no avail.

I have recently moved over to a managed dedi server and no can ask my
host to change my php.ini.

I have found out that the 'display_errors' in the php.ini is set to off
and error file logging is off.

I would like to be able log to file which is easy to do from the ini
file but also to show a custom error page if there is an error on one of
the pages.

I thought I would be able to use a custom error handler such as -

ob_start();
// custom error handler
function e($type, $msg, $file, $line) {
blah blah
ob_end_clean();

    // display error page
exit();
}

set_error_handler("e");



But all I get is a blank page. Does having display_errors off mean that
I can't use a custom error handler? I have also tried adding
*set_ini*('*display_errors*','1') but this keeps giving me a blank page.



The *s got into the email for some weird reason- they aren't in the original code. I would like an error page to be displayed for all errors including parse ones. Blank pages aren't that helpful for the user.

Sounds like a parse error (using the code above will give you that).

Try it in a htaccess file:

php_flag display_errors 1

(I think).

You can't use ini_set because a parse error breaks the whole script
and it's not executed, so you need to change this value before the
script.


Do I have to have display_errors set to 1 if I want to display a custom error page? I'd rather have display errors set to 0 but have a custom error page displayed when an error is triggered. Is this possible? Perhaps I have misunderstood how errors work in php.

You need to set this flag in a htaccess file because that gets processed before a php script does.

If you are getting a parse error on this script, setting this flag in the script won't do anything - the script won't execute at all.

By setting this particular option in a htaccess file, that gets processed before the php file does, so if you have a parse error, it will say "parse error in file X on line Y" or something to that affect - so you can move forward. You can test this manually yourself:

php -l /path/to/file.php

so you could download it to your test server, run that - see what's going on.

You could also be triggering a php or apache segfault (in which case none of this matters) - are you able to check apache error logs to see what's going on from that side of things?


If you take out your custom error handler, do you still get a blank page? That will tell us something at least..

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux