標籤:000
用.htaccess設定顯示PHP錯誤使用.htaccess可以在某種程度上更改PHP的錯誤顯示的設定,實際上,相當於更改PHP.ini的參數,很是方便。將以下相應代碼放到對應目錄中的.htaccess檔案,即可實現相應功能。關閉錯誤顯示:php_flag display_startup_errors offphp_flag display_errors offphp_flag html_errors offphp_value docref_root 0php_value docref_ext 0隻顯示PHP錯誤:php_flag display_errors onphp_flag display_startup_errors onphp_value error_reporting 2047其中,“2047”為要顯示的錯誤的層級,詳細表格如下:1 E_ERROR2 E_WARNING4 E_PARSE8 E_NOTICE16 E_CORE_ERROR32 E_CORE_WARNING64 E_COMPILE_ERROR128 E_COMPILE_WARNING256 E_USER_ERROR512 E_USER_WARNING1024 E_USER_NOTICE2047 E_ALL2048 E_STRICT4096 E_RECOVERABLE_ERROR 要把錯誤儲存到記錄檔中,可以這樣設定:# enable PHP error loggingphp_flag log_errors onphp_value error_log /home/path/public_html/domain/PHP_errors.log然後,可以設定不允許訪問.log檔案:# prevent access to PHP error log<Files PHP_errors.log> Order allow,deny Deny from all Satisfy All</Files>設定錯誤記錄檔的最大體積,以bytes為單位:# general directive for setting max error sizelog_errors_max_len integer綜合上述,.htaccess的PHP錯誤顯示設定匯總:# PHP error handling for production servers# disable display of startup errorsphp_flag display_startup_errors off# disable display of all other errorsphp_flag display_errors off# disable html markup of errorsphp_flag html_errors off# enable logging of errorsphp_flag log_errors on# disable ignoring of repeat errorsphp_flag ignore_repeated_errors off# disable ignoring of unique source errorsphp_flag ignore_repeated_source off# enable logging of php memory leaksphp_flag report_memleaks on# preserve most recent error via php_errormsgphp_flag track_errors on# disable formatting of error reference linksphp_value docref_root 0# disable formatting of error reference linksphp_value docref_ext 0# specify path to php error logphp_value error_log /home/path/public_html/domain/PHP_errors.log# specify recording of all php errorsphp_value error_reporting 999999999# disable max error string lengthphp_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>以下則是適合開發人員應用的設定:# PHP error handling for development serversphp_flag display_startup_errors onphp_flag display_errors onphp_flag html_errors onphp_flag log_errors onphp_flag ignore_repeated_errors offphp_flag ignore_repeated_source offphp_flag report_memleaks onphp_flag track_errors onphp_value docref_root 0php_value docref_ext 0php_value error_log /home/path/public_html/domain/PHP_errors.logphp_value error_reporting 999999999php_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錯誤是否顯示似乎更方便。。
原帖地址:https://sjolzy.cn/PHP-Htaccess-to-set-PHP-error-display.html
PHP - .htaccess設定顯示PHP錯誤 (轉)