php 隐藏所有错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9242903/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 06:25:35  来源:igfitidea点击:

php hide ALL errors

phpapachesecurity

提问by Frank

what are the best practises for hiding allphp errors? As I don't want ERRORS to show to the user.

隐藏所有php 错误的最佳做法是什么?因为我不希望 ERRORS 显示给用户。

I've tried using the .htacessby putting the code php_flag display_errors offin there, but it returns me a 500 error.

我已经尝试.htacess通过将代码php_flag display_errors off放在那里来使用 ,但它返回给我一个500 error.

Are there any other methods that will hide allerrors?

有没有其他方法可以隐藏所有错误?

回答by Aditya P Bhatt

to Hide All Errors:

隐藏所有错误:

error_reporting(0);
ini_set('display_errors', 0);

to Show All Errors:

显示所有错误:

error_reporting(E_ALL);
ini_set('display_errors', 1);

回答by john.w

Per the PHP documentation, put this at the top of your php scripts:

根据 PHP 文档,将其放在 php 脚本的顶部:

<?php error_reporting(0); ?>

http://php.net/manual/en/function.error-reporting.php

http://php.net/manual/en/function.error-reporting.php

If you do hide your errors, which you should in a live environment, make sure that you are logging any errors somewhere. How to log errors and warnings into a file?Otherwise, things will go wrong and you will have no idea why.

如果您确实隐藏了错误(您应该在实时环境中这样做),请确保在某处记录任何错误。如何将错误和警告记录到文件中?否则,事情会出错,你将不知道为什么。

回答by axiomer

In your php file just enter this code:

在您的 php 文件中输入以下代码:

error_reporting(0);

This will report no errors to the user. If you somehow want, then just comment this.

这不会向用户报告任何错误。如果您想以某种方式想要,那么只需对此发表评论。

回答by Stewie

Use PHP error handling functions to handle errors. How you do it depends on your needs. This system will intercept all errors and forward it however you want it Or supress it if you ask it to do so

使用 PHP 错误处理函数来处理错误。你怎么做取决于你的需要。该系统将拦截所有错误并根据您的需要转发它或者如果您要求它这样做则抑制它

http://php.net/manual/en/book.errorfunc.php

http://php.net/manual/en/book.errorfunc.php

回答by TimWolla

The best way is to build your script in a way it cannot create any errors! When there is something that can create a Notice or an Error there is something wrong with your script and the checking of variables and environment!

最好的方法是以不会产生任何错误的方式构建脚本!当存在可以创建通知或错误的内容时,您的脚本以及变量和环境的检查有问题!

If you want to hide them anyway: error_reporting(0);

如果您无论如何都想隐藏它们: error_reporting(0);