Turn off display errors using file “php.ini”

前端 未结 12 1432
春和景丽
春和景丽 2020-11-28 06:59

I am trying to turn off all errors on my website. I have followed different tutorials on how to do this, but I keep getting read and open error messages. Is there something

12条回答
  •  伪装坚强ぢ
    2020-11-28 07:45

    I always use something like this in a configuration file:

    // Toggle this to change the setting
    define('DEBUG', true);
    
    // You want all errors to be triggered
    error_reporting(E_ALL);
    
    if(DEBUG == true)
    {
        // You're developing, so you want all errors to be shown
        display_errors(true);
    
        // Logging is usually overkill during development
        log_errors(false);
    }
    else
    {
        // You don't want to display errors on a production environment
        display_errors(false);
    
        // You definitely want to log any occurring
        log_errors(true);
    }
    

    This allows easy toggling between debug settings. You can improve this further by checking on which server the code is running (development, test, acceptance, and production) and change your settings accordingly.

    Note that no errors will be logged if error_reporting is set to 0, as cleverly remarked by Korri.

提交回复
热议问题