Header Redirect不起作用。代码在iar-calculator.php
文件下,代码适用于第二个elseif
,但由于其他两个文件位于不同的目录或文件夹中。我试过使用../folder name/page.php
,`folder-name/page.php ``。这两种方法在我的情况下都不起作用。我该怎么修?感谢
//重定向
if(isset($_POST['cmd_submit'])){
if(($_POST['tire'] == "rear") && ($_POST['tractor'] == "2wd" || $_POST['tractor'] == "4wd")){
//redirect here
header('location:iar-calculator.php');
}
elseif(($_POST['tire'] == "rear") && ($_POST['tractor'] == "mfwd")){
//redirect here
header('location:index.php');
}
elseif(($_POST['tire'] == "front") && ($_POST['tractor'] == "2wd" || $_POST['tractor'] == "4wd")){
//redirect here
header('location:front/index.php');}
elseif(($_POST['tire'] == "front") && ($_POST['tractor'] == "mfwd")){
//redirect here
header('location:front/iar-calc-rear.php');
}
else{
}
}
//HTML代码
<form method="post" style="padding: 10px 0px 10px 5px;">
<select name="tire" style="width:100px;display:inline;height: 30px;" class="first">
<option value="">Select</option>
<option value="rear">Rear Tire</option>
<option value="front">Front Tire</option>
</select>
<select name="tractor" style="width:100px;height: 30px;display:inline" class="second" disabled>
<option value="">select Type</option>
<option value="2wd">2WD</option>
<option value="mfwd">MFWD</option>
<option value="4wd">4WD</option>
</select>
<input type="submit" value="Go" name="cmd_submit" />
?>
Header函数必须是加载页面中的第一个。添加
ob_start();
后的第一行
<?php
ob_start使服务器等待,然后加载整个页面,如果它找到header(),它将作为第一个命令执行。如果添加ob_start();在顶部,您可以在任何需要的地方使用header()