error content should be written in seperate file

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

  1. #1
    I wants to know about log_errors in php(error messages in php)

    with some example codings

    I need to know some phpcoding
    when an error occurs in php page, I need to set the errormessages and i want to write that error messages in the seperate file,not in the browser
     
    kumar84, Jun 20, 2007 IP
  2. UnrealEd

    UnrealEd Peon

    Messages:
    148
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    My reply in your other thread is bout storing the errors instead of dislpaying them. Here's the code again:
    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:
    The error_log function writes the error to the server log. If you make some changes to the functio, you can make it to write the error to a different file.

    This is how you add data to file in php:
    $fp = fopen("myfile.log", "a+");
    fwrite($fp, $message);
    fclose($fp);
    PHP:
     
    UnrealEd, Jun 21, 2007 IP