reason for error display in the server

Discussion in 'PHP' started by kumar84, Jun 20, 2007.

  1. #1
    In php why we should go for diplaying the errors in the server by means of error_log ,without displaying in the browser
     
    kumar84, Jun 20, 2007 IP
  2. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Security reasons. You can give away info that you don't want users to know in error messages. Also, they are not nice to look at :D
     
    krt, Jun 20, 2007 IP
  3. UnrealEd

    UnrealEd Peon

    Messages:
    148
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It is best to set track_errors to On if your gonna stop displaying errors. Otherwise you can never know when an error occured while processing your script. If you use track_errors, the error is stored in a php variable named $php_errormsg (not 100% sure it's called this way, but it should be something similar), and you will have to check at certain points in your script if an error occured (which is kinda redundant, as you will have to kill your script at that point, which is exactly the same as what the default error handler does).

    A better way to get rid of the errors, is to create your own error handler. Here's a small example:
    set_error_handler("my_error_handler");
    
    function my_error_handler ($errNo, $errString, $errFile, $errLine) {
      // if you don't allready store the error in the error log:
      error_log("[" . $errNo . "] " . $errString. ": in " . $errFile . " @line " . $errLine);
    
      // now dislpay a custom error message:
      die("Something went wrong processing this page, the webmaster has been informed");
    }
    PHP:
    This will stop the output of the php errors, but allows you to display custom errors, which is a lot nicer, as you can simply output an error html page.
     
    UnrealEd, Jun 21, 2007 IP