Stop printing php error messages to browser

2020-03-12 03:33发布

I'm using PHP 5.3, CentOS 6.2, httpd 2.2.15, NetBeans 7.0.1 (running remotely via ftp).

I want to stop printing error messages to the browser, it's enough that it prints to the error_log of httpd.

I thought by doing try/catch I would decide on my own how to handle the error but it still prints to both error_log and browser.

function smic_gettext($phrase){

        try{
            $tr_text = $this->language_array[$phrase];

        } catch(Exception $e){
            error_log("Couldn't find any entry in the translation file for ".$phrase.". ".$e);
            return $phrase;

        }

        return $tr_text;
    } 

How should I configure in order to stop this behaviour?

I have tried setting display_errors=Off and display_errors=0 in php.ini. No difference (I did restart httpd).

8条回答
兄弟一词,经得起流年.
2楼-- · 2020-03-12 04:05

You need to change the php.ini setting display_errors to off or 0. You can either do this in your actual php.ini, with a .htaccess file, or by calling this at the start of the script:

ini_set('display_errors', '0');
查看更多
Animai°情兽
3楼-- · 2020-03-12 04:14

If error appears only in one line it is possible to prevent error display with adding sign @ to start of that line.

@YOUR_CUSTOM_COMMAND

Example:

@file_get_contents('custom_file.txt');
查看更多
ら.Afraid
4楼-- · 2020-03-12 04:19

Wheter or not PHP errors are sent to the browser is determined by the php.ini setting: display_errors. Set it to Off to avoid it being output. This file is usually located under /etc/php.ini or /etc/php5/php.ini

查看更多
贼婆χ
5楼-- · 2020-03-12 04:19
神经病院院长
6楼-- · 2020-03-12 04:20

Try adding the following to the top of your script:

ini_set('display_errors',0);

This should set the error reporting to none and override the servers php.ini settings (which sometimes ignore your error_reporting(0) )

查看更多
Ridiculous、
7楼-- · 2020-03-12 04:23
display_errors = Off

in php.ini will let you keep your syslog errors, but write nothing to the browser.

查看更多
登录 后发表回答