大家會經常遇到頁面空白的現象,其實這是由於 PHP 在運行的時候遇到了錯誤信息終止了運行,而我們的配置參數又禁止 PHP 想頁面輸出錯誤信息的報告,所以大家看到的頁面就是空白的,那麼看到 PHP 報告的錯誤信息呢?大家可以根據下面的教程來開啓。

一、通過配置 php.ini 中的參數設置 PHP 的報錯級別

可以在 php.ini 中適當的位置增加一行

error_reporting = E_ALL

  • <P>error_reporting  =  E_ALL </P>

注: 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

  • <P>; Examples:</P><P>;   - Show all errorsexcept for notices and coding standards warnings</P><P>;error_reporting E_ALL & ~E_NOTICE</P><P>;   - Show all errorsexcept for notices</P><P>;error_reporting E_ALL & ~E_NOTICE E_STRICT</P><P>;   - Show only errors</P><P>;error_reporting E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR</P><P>;   - Show all errors except for notices and coding standards warnings</P><P>;error_reporting  =  E_ALL & ~E_NOTICE</P>

我只要在這些行代碼的下面增加 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);

  • <P>//禁用錯誤報告</P><P>error_reporting(0);</P><P>//報告運行時錯誤</P><P>error_reporting(E_ERROR | E_WARNING | E_PARSE);</P><P>//報告所有錯誤</P><P>error_reporting(E_ALL);</P>

那麼我們就可以把論壇裏的 include/common.inc.php 文件裏的

error_reporting(0);

  • <P>error_reporting(0);</P>

修改成

error_reporting(E_ALL);

  • <P>error_reporting(E_ALL);</P>

然後保存,這樣就可以看到 PHP 報告的錯誤信息了