大家會經常遇到頁面空白的現象,其實這是由於 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 報告的錯誤資訊了