可能重复:
PHP: “Notice: Undefined variable” and “Notice: Undefined index”代码抛出警告:未定义指数在GET数组
此代码显示了*标记行警告,因此无需使用任何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
这里是警告 “通知:未定义指数:页:\ WWW \ Apachi_xampp \ SETUP \ XAMPP \ htdocs中\的index.php上线284”
在此先感谢。
请用更直观的问题标题:) – Spyros 2012-03-26 07:05:29
什么是错误/警告你?你的问题真的会被粉碎。 – gideon 2012-03-26 07:07:00
这是一个很好的问题。标题很好。问题就像他说的:$ _GET ['page']将返回一个警告,如果在'_GET中找不到'page'索引。所以解决方案是在尝试检索值之前测试它是否已设置。最快的方法可能是使用Telulz或Kuipers建议的三元条件。 – Stefan 2012-03-26 07:27:32