有人可以解释为什么在调用 header($URL) 时,此代码中的 $URL 变量总是设置为“Location:unknown.php”吗?:如果我在第一行中注释掉声明/初始化,则代码有效,但我收到一个变量未声明的警告(如果我在 if 块之前声明 $URL 而不初始化它,我也会收到这些警告)。
$URL = 'Location: unknown.php';
if ($spring){
if (($leaves)&&(!$stem)&&(!$root)&&(!$head)&&(!$whole)){$URL = 'Location: snow-mold.php';}
} else if ($other) {
if ((!$leaves)&&(!$stem)&&(!$root)&&($head)&&(!$whole)){$URL = 'Location: o01.php';}
if (($whole) || ($root) ){$URL = 'Location: o02.php';}
if (($leaves)&&($stem)&&(!$root)&&($head)&&(!$whole)){$URL = 'Location: o03.php';}
if (($leaves)&&($stem)&&(!$root)&&(!$head)&&(!$whole)){$URL = 'Location: o04.php';}
if ((!$leaves)&&($stem)&&(!$root)&&($head)&&(!$whole)){$URL = 'Location: o03.php';}
if (($leaves)&&(!$stem)&&(!$root)&&($head)&&(!$whole)){$URL = 'Location: o05.php';}
if ((!$leaves)&&($stem)&&(!$root)&&(!$head)&&(!$whole)){$URL = 'Location: o06.php';}
if (($leaves)&&(!$stem)&&(!$root)&&(!$head)&&(!$whole)){$URL = 'Location: o07.php';}
}
header($URL);
好的,我已经简化了代码以突出显示问题...
$spring = (isset($_POST['season']) && strcmp($_POST['season'],'spring') == 0);
$URL = 'Location: unknown.php';
if ($spring){
$URL = 'Location: snow-mold.php';
}
header($URL);
总是重定向到 unknown.php。If I change $URL = 'Location: unknown.php'
to $URL;
, the code redirects to snow-mold.php if and only if spring is selected, But I get a $URL undefined warning.