问题描述:

Header Redirect doesn't work when i try to redirect to file outside of the same directory where the file with code is located. The code is under iar-calculator.php file the code works for second elseif but since the others two files are in different directory or folder. i tried using ../folder name/page.php,`folder name/page.php``. both doesnt work in my case. How can i fix it? Thanks

//Redirection

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 code

 <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 function must be first in loaded page. Add

ob_start();

on first line after

<?php

ob_start makes, that server wait, then you load whole page, and if it find header(), it will do it as first command. If you add ob_start(); at the top, then you can have header() anywhere you want

相关阅读:
Top