2012-01-23 187 views
-7

正如標題指出:有沒有辦法阻止html警告?

Warning: getimagesize failed to open, etc 

有沒有辦法忽略這些,意味着不打印出來?原因是,我基本上不關心,他們是非常罕見的,我在測試顯然做的,但如果這樣做了,我寧願設置代碼給我發電子郵件比閃了大丑的信息給用戶。

問題適用於由任何方式警告。

+7

關閉php.ini中的'display_errors'或在代碼中執行'ini_set('display_errors',0)''。但是,真的,你應該修復代碼,使它們不在第一位發佈。 –

+2

請參閱http://docs.php.net/manual/en/function.error-log.php,瞭解如何配置電子郵件日誌記錄 – Gordon

+0

您可以編輯您的php.ini,並禁用'display_errors'或更改'error_reporting'不顯示警告。我不太記得確切的設置,但你可以在php.ini上找到它。無論如何,你應該嘗試修復這些錯誤:) – jere

回答

1

他們是PHP錯誤,你可以通過改變你的PHP INI設置將其關閉,搜索display_errors

display_errors = Off

6

有幾種不同的方式:

  • 設置一個custom error handler(最好的方法,讓你做一些有用的東西像電子郵件的錯誤,而你自己)
  • ini_set('display_errors', false);
  • 完全
  • Surpress錯誤通過@操作:@getimagesize(...);
2

許多方面存在着,這裏有幾個...

error_reporting(0); //Will hide all errors from hapenning 

最終,你只能關閉E_WARNING但這需要一些布爾數學從當前的error_reporting()設置中僅排除E_WARNING。

另一種方法是把一個@符號在你想隱藏的錯誤操作的面前:

$returnvalue = @getimagesize($params); 

這將防止錯誤顯示...

最後的辦法是關閉錯誤顯示使用:

ini_set('display_errors', 0); 

但這樣,所有錯誤,警告,通知都被隱藏。他們仍然登錄到錯誤日誌文件。

最後警告我可能想給你的是,從來沒有與具有錯誤的可能性代碼。總有一些驗證可以做,應該做。關閉錯誤或忽略它們通常是不好的,當你嘗試修復,並且出現是因爲你決定簡單地隱藏潛在的錯誤問題,可能會導致艱辛後..

好運

0

我假設有這裏涉及一些PHP。您可以通過配置您的php.ini(php配置文件)文件來更改錯誤報告。您可以關閉錯誤報告功能,將其留作警告和通知,將其保留在錯誤狀態或讓其保持全部狀態。

通知和警告不會造成大問題,或從運行保持腳本。致命錯誤雖然會阻止腳本運行。

所以你的PHP之內。ini文件,尋找這一行:

的error_reporting = E_ERROR,並將其更改爲以下情況之一,或它們的組合:

E_ALL    - All errors and warnings 
E_ERROR   - fatal run-time errors 
E_WARNING   - run-time warnings (non-fatal errors) 
E_PARSE   - compile-time parse errors 
E_NOTICE   - run-time notices (these are warnings which often result 
        from a bug in your code, but it's possible that it was 
        intentional (e.g., using an uninitialized variable and 
        relying on the fact it's automatically initialized to an 
        empty string) 
E_CORE_ERROR  - fatal errors that occur during PHP's initial startup 
E_CORE_WARNING - warnings (non-fatal errors) that occur during PHP's 
        initial startup 
E_COMPILE_ERROR - fatal compile-time errors 
E_COMPILE_WARNING - compile-time warnings (non-fatal errors) 
E_USER_ERROR  - user-generated error message 
E_USER_WARNING - user-generated warning message 
E_USER_NOTICE  - user-generated notice message 

通過將該值設置爲E_ERROR,警告和聲明將不被顯示。只會顯示錯誤。

0

您可以使用您的網頁error_reporting(0);

,或者您也可以使用.htaccess文件和php.ini設置錯誤報告了。

相關問題