使用文件"php.ini"关闭显示错误. [英] Turn off display errors using file "php.ini"

查看:73
本文介绍了使用文件"php.ini"关闭显示错误.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试关闭网站上的所有错误.我遵循了有关如何执行此操作的不同教程,但是我一直在阅读并打开错误消息.有什么我想念的吗?

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 I am missing?

我在 php.ini 文件中尝试了以下操作:

I have tried the following in my php.ini file:

;Error display
display_startup_errors = Off
display_errors = Off
html_errors = Off
docref_root = 0
docref_ext = 0

由于某种原因,当我对不存在的文件执行fileopen()调用时,仍然显示错误.出于显而易见的原因,这对于实时网站来说并不安全.

For some reason when I do a fileopen() call for a file which does not exist, I still get the error displayed. This is not safe for a live website, for obvious reasons.

推荐答案

我总是在配置文件中使用以下内容:

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.

请注意,如果将error_reporting设置为0(Korri巧妙地指出),则不会记录任何错误.

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

这篇关于使用文件"php.ini"关闭显示错误.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆