Turn off display errors using file “php.ini”

前端 未结 12 1267
春和景丽
春和景丽 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:44

    I usually use PHP's built in error handlers that can handle every possible error outside of syntax and still render a nice 'Down for maintenance' page otherwise:

    Format PHP error on production server

    0 讨论(0)
  • 2020-11-28 07:44

    It's been quite some time and iam sure OP's answer is cleared. If any new user still looking for answer and scrolled this far, then here it is.

    Check your updated information in php.ini file

    Using Windows explorer:

    C/xampp/php/php.ini
    

    Using XAMPP Control Panel

    1. Click the Config button for 'Apache' (Stop | Admin | Config | Logs)
    2. Select PHP (php.ini)

    Can i create my own phpinfo()? Yes you can

    1. Create a phpinfo.php in your root directly or anywhere you want
    2. Place this <?php phpinfo(); ?>
    3. Save the file.
    4. Open the file and you should see all the details.

    How to set display_errors to Off in my own file without using php.ini

    You can do this using ini_set() function. Read more about ini_set() here (https://www.php.net/manual/en/function.ini-set.php)

    1. Go to your header.php or index.php
    2. add this code ini_set('display_errors', FALSE);

    To check the output without accessing php.ini file

    $displayErrors = (ini_get('display_errors') == 1) ? 'On' : 'Off';
    $PHPCore = array(
        'Display error' => $displayErrors
        // add other details for more output
    );
    foreach ($PHPCore as $key => $value) {
        echo "$key: $value";
    }
    
    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-11-28 07:45

    It is not enough in case of PHP fpm. It was one more configuration file which can enable display_error. You should find www.conf. In my case it is in directory /etc/php/7.1/fpm/pool.d/

    You should find php_flag[display_errors] = on and disable it, php_flag[display_errors] = off. This should solve the issue.

    0 讨论(0)
  • 2020-11-28 07:47

    Open your php.ini file (If you are using Linux - sudo vim /etc/php5/apache2/php.ini)

    Add this lines into that file

       error_reporting = E_ALL & ~E_WARNING 
    

    (If you need to disabled any other errors -> error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE & ~E_WARNING)

        display_errors = On
    

    And finally you need to restart your APACHE server.

    0 讨论(0)
  • 2020-11-28 07:50

    In php.ini, comment out:

    error_reporting = E_ALL & ~E_NOTICE
    error_reporting = E_ALL & ~E_NOTICE | E_STRICT
    error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ER… _ERROR
    error_reporting = E_ALL & ~E_NOTICE
    

    By placing a ; ahead of it (i.e., like ;error_reporting = E_ALL & ~E_NOTICE)

    For disabling in a single file, place error_reporting(0); after opening a php tag.

    0 讨论(0)
提交回复
热议问题