可能重复:
PHP: “Notice: Undefined variable” and “Notice: Undefined index”
此代码在*标记的行上显示警告,所以任何想法都不使用ini_set("display_errors", 0);
?
只需要任何替代代码......
$page = $_GET['page']; // gets the variable $page ******
//global $page;
if (!empty($page)){
include($page);
} // if $page has a value, include it
else {
include("home.php");
} // otherwise, include the default page
以下是警告“通知:未定义索引:第284行:\ www \ Apachi_xampp \ setup \ xampp \ htdocs \ index.php中的页面”
提前致谢。
答案 0 :(得分:4)
你确定它是一个警告,而不是一个通知说"不明索引"? 试试这个:
$page = (isset($_GET['page']) ? $_GET['page'] : '');
答案 1 :(得分:1)
因为如果没有在URL中设置?页面参数,它将抛出该错误。替换为以下代码:
$page = (isset($_GET['page'])) ? $_GET['page'] : ''; // gets the variable $page ******
//global $page;
if (!empty($page)){
include($page);
} // if $page has a value, include it
else {
include("home.php");
} // otherwise, include the default page
答案 2 :(得分:0)
if(isset($_GET['page'])){
$page = $_GET['page'];
if(!empty($page)){
include($page);
}else{
include("home.php");
}
}