1

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" />

?>
Kin
  • 145
  • 1
  • 11
  • You are setting an HTTP header, and its content should be a valid, fully qualified URL. – miken32 Apr 05 '16 at 22:26
  • @miken32 i am sorry I dont get it where should i put it? – Kin Apr 05 '16 at 22:27
  • I'm saying you need a full URL. – miken32 Apr 05 '16 at 22:27
  • @miken32 I tired that too, no luck. i tried using `header("Location: http://www.google.com/"); /* Redirect browser */ } ` this still doesnt work – Kin Apr 05 '16 at 22:29
  • Possible duplicate of [How to make a redirect in PHP?](http://stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php) – miken32 Apr 05 '16 at 22:31
  • If redirects aren't working for you, make sure you aren't outputting any text at all before the call the `header()`. Likely if you look at the log files you'll see an error telling you as much. – miken32 Apr 05 '16 at 22:32
  • I dont know still doesn't work – Kin Apr 05 '16 at 22:41

1 Answers1

0

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

Kaspy
  • 54
  • 1
  • 10