Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12

Thread: I need help preventing PHP errors from displaying in the browser

  1. #11
    huluganfantasy is offline Junior Member
    Join Date
    Aug 2016


    Quote Originally Posted by karl94 View Post
    Could you please provide the complete code needed to reproduce the issue? Which error are you trying to catch exactly? You should include that in the code, otherwise is difficult to help you.
    You can test it with any fatal error, Karl. For example, if I add the line:

    <?php doesnt_exist();?>

    anywhere in any page, the page will render partially up to this line, then write the error in my log correctly ("Call to undefined function doesnt_exist()"),then stop immediately with a partially rendered page. It never redirects. If I place the undefined function at the top of the page, it will write the error in the log correctly but stop on a blank page. In my development environment it follows the redirect to the custom error page each time. Note that I am turning on buffering with ob_start(), before anything is output.

    Quote Originally Posted by karl94 View Post
    Why did you include that if inside fatalHandler? That way you can't catch parse errors, for instance.
    I followed the links you provided to Stack exchange above, and from what is said on that site, the fatal handler can't be used to catch parse errors, unless the error occurs in an included file. I would have to make all my site pages includes in some other page for that to work. In fact, I tested this by changing "E_ERROR" to "E_PARSE", in the fatalHandler() above, then intentionally leaving out a semi-colon. When I did this the fatal handler did not work in my development environment (it did not log anything or redirect anywhere). I was also told on Stack Exchange that when I register a function using register_shutdown_function, if I don't give the function any constraints (such as the if statement above), PHP will invoke the function every time my script finishes executing. So the purpose of the if statement is to stop it from running when the error is not fatal, or there is no error at all.
    Last edited by huluganfantasy; 09-13-2016 at 06:16 AM.

  2. #12
    lettingthedaysgoby is offline Junior Member
    Join Date
    Mar 2018


    Quote Originally Posted by huluganfantasy View Post
    Please read my post again Karl. I am not "hiding" any problems. I want errors recorded in a log. I can easily check the log and fix any errors. I do not want errors displayed because it puts a map of my site folders, folder names and server-side code in every viewer's browser. That is a security risk, AND very unprofessional. Thanks for your help.

    EDIT It's also not efficient, because I won't see errors other site visitors encounter, unless those errors are recorded in a log. I can't see their browser
    Security through obscurity isn't security at all. Sorry for the bump, but that's security 101.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts