問題描述
我正在開發 Wordpress 外掛。當我啟用我的外掛,我得到一個訊息
The plugin generated 293 characters of unexpected output during activation. If you notice 「headers already sent」 messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.
外掛工作非常好,但我不知道為什麼我得到這個訊息。我的外掛是:http://wordpress.org/extend/plugins/facebook-send-like-button/
最佳解決方案
我的猜測是你收到一個 PHP 錯誤,它會在標頭檔案傳送之前生成輸出。如果啟用了 E_NOTICE,如果未設定該變數,則呼叫 $_POST['foo']可能會生成 「Notice:undefined variable」 錯誤。
最佳實踐:從不承擔 GET,POST,COOKIE 和 REQUEST 變數的任何內容。始終使用 isset()或 empty()進行檢查。
if ( isset( $_POST['foo'] ) ) {
$foo = (string) $_POST['foo'];
// apply more sanitizations here if needed
}
次佳解決方案
這通常是在開啟<?php 標記之前或關閉?> 標記之後由空格或新行引起的。
檢視此頁面以檢視一些解決方案:How do I solve the Headers already sent warning problem?
UPDATE
檢查你的外掛程式碼後,我注意到的一點是你沒有關閉 PHP 標籤。在最後一行,新增?>
第三種解決方案
我以前面臨過同樣的問題,對我來說這是一個額外的空白。當我刪除所有這些空格後,外掛可以啟用,沒有任何錯誤/警告。
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。