使用.htaccess更改PHP的错误显示的设置,相当于更改PHP.ini的参数,相当方便。
将以下代码放到对应目录中的.htaccess文件。
1,关闭错误显示 :
2,只显示PHP错误 :
其中,“2047”为要显示的错误的级别。
错误代码与错误类型的对应关系,如下:
3,把错误保存到日志文件中,可以这样设置:
然后,可以设置不允许访问.log文件 :
设置错误日志的最大体积,以bytes为单位:
4,.htaccess的PHP错误显示设置汇总 :
# PHP error handling for production servers
# disable display of startup errors
php_flag display_startup_errors off
# disable display of all other errors
php_flag display_errors off
# disable html markup of errors
php_flag html_errors off
# enable logging of errors
php_flag log_errors on
# disable ignoring of repeat errors
php_flag ignore_repeated_errors off
# disable ignoring of unique source errors
php_flag ignore_repeated_source off
# enable logging of php memory leaks
php_flag report_memleaks on
# preserve most recent error via php_errormsg
php_flag track_errors on
# disable formatting of error reference links
php_value docref_root 0
# disable formatting of error reference links
php_value docref_ext 0
# specify path to php error log
php_value error_log /home/path/public_html/domain/PHP_errors.log
# specify recording of all php errors
php_value error_reporting 999999999
# disable max error string length
php_value log_errors_max_len 0
# protect error log by preventing public access
<Files /home/path/public_html/domain/PHP_errors.log>
Order allow,deny
Deny from all
Satisfy All
</Files>
5,附适合开发者应用的设置:
# PHP error handling for
development servers
php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on
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 999999999
php_value log_errors_max_len 0
<Files /home/path/public_html/domain/PHP_errors.log>
Order allow,deny
Deny from all
Satisfy All
</Files>
以上介绍了几种不同情况下,通过.htaccess设置显示PHP错误来控制PHP错误是否显示的方法,简便好用,建议朋友们试试。