2007/05/22

Apache log 中出現 PHP Notice: Undefined index 的解決方式

在使用外部傳遞變數 $_POST 或 $_GET

Apache log 中有可能出現 PHP Notice: Undefined index

解決方式一種是直接在 php configuration file 內

錯誤紀錄的階級修改為

error_reporting = E_ALL & ~E_NOTICE


另一種則是保持好習慣

用到可能沒傳遞的變數做好判斷

範例如下:

[php] if( isset($_POST['p']) ) {
$post_p = $_POST['p'];
echo "get variable {$post_p} by POST method";
}
?>[/php]

No comments:

Post a Comment