如何在 .htaccess 文件中禁用 PHP 中的通知和警告?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8652933/
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
How can I disable notices and warnings in PHP within the .htaccess file?
提问by nic
I just want to only turn on PHP errors and disable all notices and warnings in PHP files.
我只想打开 PHP 错误并禁用 PHP 文件中的所有通知和警告。
回答by imp
It is probably not the best thing to do. You need to at least check out your PHP error log for things going wrong ;)
这可能不是最好的做法。你至少需要检查一下你的 PHP 错误日志是否有问题;)
# PHP error handling for development servers
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_flag log_errors on
php_flag ignore_repeated_errors off
php_flag ignore_repeated_source off
php_flag report_memleaks on
php_flag track_errors on
php_value docref_root 0
php_value docref_ext 0
php_value error_log /home/path/public_html/domain/PHP_errors.log
php_value error_reporting -1
php_value log_errors_max_len 0
回答by Fortes
If you are in a shared hosting plan that doesn't have PHP installed as a module you will get a 500 server error when adding those flags to the .htaccess file.
如果您使用的共享主机计划没有将 PHP 作为模块安装,那么在将这些标志添加到 .htaccess 文件时,您将收到 500 服务器错误。
But you can add the line
但是您可以添加该行
ini_set('display_errors','off');
on top of your .php file and it should work without any errors.
在您的 .php 文件之上,它应该可以正常工作而不会出现任何错误。
回答by Sudhir Bastakoti
Try:
尝试:
php_value error_reporting 2039
回答by Rich
Fortes is right, thank you.
福特是对的,谢谢。
When you have a shared hosting it is usual to obtain an 500 server error
.
当您拥有共享主机时,通常会获得500 server error
.
I have a website with Joomlaand I added to the index.php
:
我有一个Joomla网站,我添加了index.php
:
ini_set('display_errors','off');
The error line showed in my website disappeared.
我网站上显示的错误行消失了。
回答by Mohamed Badr
I used ini_set('display_errors','off');
and it worked great.
我用过ini_set('display_errors','off');
,效果很好。
回答by user5637954
Use:
用:
ini_set('display_errors','off');
It is working fine in WordPress' config.php
.
它在 WordPress' 中运行良好config.php
。