我們在瀏覽一些論壇的時候會經常遇到打開網頁是空白的情況,其實是由于php在運行過程中遇到錯誤信息而致,如果想知道那個環節出了問題就得讓php顯示錯誤信息。大家可以參考下面php顯示錯誤信息的方法。
一、通過配置 php.ini 中的參數設置PHP的報錯級別
可以在 php.ini 中適當的位置增加一行
error_reporting = E_ALL
CODE: [COPY]
error_reporting = E_ALL
注: php.ini 中實現給出了一些例子,比如我本地的 php.ini 中就有如下
; Examples:
; - Show all errors, except for notices and coding standards warnings
;error_reporting = E_ALL & ~E_NOTICE
; - Show all errors, except for notices
;error_reporting = E_ALL & ~E_NOTICE | E_STRICT
; - Show only errors
;error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
; - Show all errors except for notices and coding standards warnings
;error_reporting = E_ALL & ~E_NOTICE
CODE: [COPY]
; Examples:
; - Show all errors, except for notices and coding standards warnings
;error_reporting = E_ALL & ~E_NOTICE
; - Show all errors, except for notices
;error_reporting = E_ALL & ~E_NOTICE | E_STRICT
; - Show only errors
;error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
; - Show all errors except for notices and coding standards warnings
;error_reporting = E_ALL & ~E_NOTICE
我只要在這些行代碼的下面增加 error_reporting = E_ALL 然后重新啟動 web 服務就可以了
二、通過 PHP 函數 error_reporting 設定 PHP 報錯級別
如果你無權修改 php.ini 中的參數配置,你可以通過這個函數來設置報錯級別。
error_reporting() 函數使用方法
error_reporting(report_level)
如果參數 level 未指定,當前報錯級別將被返回。
任意數目的以上選項都可以用“或”來連接(用 OR 或 |),這樣可以報告所有需要的各級別錯誤。例如,下面的代碼關閉了用戶自定義的錯誤和警告,執行了某些操作,然后恢復到原始的報錯級別:
//禁用錯誤報告
error_reporting(0);
//報告運行時錯誤
error_reporting(E_ERROR | E_WARNING | E_PARSE);
//報告所有錯誤
error_reporting(E_ALL);
CODE: [COPY]
//禁用錯誤報告
error_reporting(0);
//報告運行時錯誤
error_reporting(E_ERROR | E_WARNING | E_PARSE);
//報告所有錯誤
error_reporting(E_ALL);
那么我們就可以把論壇里的 include/common.inc.php文件里的
error_reporting(0);
CODE: [COPY]
error_reporting(0);
新聞熱點
疑難解答