【发布时间】:2013-09-06 02:37:36
【问题描述】:
在你问之前,是的,在问这个问题之前,我已经搜索了近 20 个关于 SO 的不同“未定义索引”问题。可悲的是,他们都没有给我解决问题的线索。我有一个简单的 index.php 文件,它根据您按下的链接切换不同的 html 文件。在一个似乎完全没有问题的实时服务器上,但是当我使用 Xampp 时,我收到一长串“未定义的索引”,我不知道为什么。我的 Index.php 文件如下。未定义索引消息指出“每一行中的未定义索引 rv”。
<?php
include ("anime_header.html");
if($_GET['rv'] == "amnesia") include ("Amnesia.html");
else if($_GET['rv'] == "shingeki") include ("AttackOnTitan.html");
else if($_GET['rv'] == "chuunibyou") include ("Chuunibyou.html");
else if($_GET['rv'] == "crimeedge") include ("CrimeEdge.html");
else if($_GET['rv'] == "datealive") include ("DateALive.html");
else if($_GET['rv'] == "duskmaiden") include ("DuskMaiden.html");
else if($_GET['rv'] == "gargantia") include ("Gargantia.html");
else if($_GET['rv'] == "K_anime") include ("K_Anime.html");
else if($_GET['rv'] == "karneval") include ("Karneval.html");
else if($_GET['rv'] == "kotoura") include ("Kotoura-San.html");
else if($_GET['rv'] == "kaibutsu") include ("LittleMonster.html");
else if($_GET['rv'] == "nerawareta") include ("Nerewareta.html");
else if($_GET['rv'] == "redgarden") include ("RedGarden.html");
else if($_GET['rv'] == "saikano") include ("Saikano.html");
else if($_GET['rv'] == "sakurasou") include ("Sakurasou.html");
else if($_GET['rv'] == "sasamisan") include ("Sasami-San.html");
else if($_GET['rv'] == "vividred") include ("Vividred.html");
else include ("animereviews.html");
include ("ReviewFooter.html");
?>
我不是在寻找一种方法来抑制错误消息,而是了解它为什么只出现在我的 Xampp 服务器上以及将来如何修复它。
【问题讨论】:
-
将输入复制到一个临时变量一次,然后比较。最好使用
switch或数组映射。 -
消息很清楚:变量 $_GET['rv'] 未设置。至于为什么会这样,您必须查看用于链接到此页面的方法,并确保查询字符串中有
rv=something。 -
On a live server that seems to be no problem这是因为在实时服务器上,您禁用了警告。如果您打开 error_reporting,您应该会再次看到您看到的错误,就像在 XAMPP 上一样。 -
通知中应该有一个文件名和一个行号。使用这些信息来缩小问题范围。
标签: php xampp undefined-index