0

I have been scratching my head around this for a while. What i'm trying to do is redirect people to different pages based on the result of a survey. WHen i test it on my local computer it works perfectly and redirects the the appropriate page but when i put the code on my server, it stops working and just its on the page. There are nor errors logged in: Here is the code example:

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);

$data[0]= ($_GET['demo']);
$data[1]=$_GET['energy'];
$data[2]=$_GET['openness'];
$data[3]=$_GET['literacy'];


$meanenergy = $data[1] / 160;

$meanopenness = $data[2] / 16;

$meanliteracy = $data[3] /16;


if ($meanenergy <=0.5 && $meanopenness >0.5 && $meanliteracy <=0.5){

  header("Location: http://domain/survey_result/Determined-Doer/");

}elseif ($meanenergy <=0.5 && $meanopenness >0.5 && $meanliteracy >=0.5){

  header("location:http://domain/survey_result/Comfortable-Cruiser/");

} elseif ($meanenergy >=0.5 && $meanopenness >0.5 && $meanliteracy <=0.5){

  header("location:http://domain/survey_result/Diligent-Planner/");

}elseif ($meanenergy >=0.5 && $meanopenness >0.5 && $meanliteracy >=0.5){

  header("location:http://domain/survey_result/Financial-Freestyler/");

}elseif ($meanenergy <=0.5 && $meanopenness <0.5 && $meanliteracy <=0.5){

  header("location:http://domain/survey_result/bold-adventurer/");

}elseif ($meanenergy <=0.5 && $meanopenness <0.5 && $meanliteracy >=0.5){

  header("location:http://domain/survey_result/Energetic-Explorer/");

}elseif ($meanenergy >=0.5 && $meanopenness <0.5 && $meanliteracy <=0.5){

  header("location:http://domain/survey_result/Sensible-Optimist/");

}else{

  header("location:http://domain/survey_result/LaidBack-Observer/");

}





?>
  • Move your php code at the top of your HTML content. – Karlo Kokkak May 28 '18 at 04:52
  • 2
    you can't have any output before header() –  May 28 '18 at 04:53
  • @KarloKokkak Even if is trip all of the html away and only have PHP code it still does not work. – Vinay Sharma May 28 '18 at 05:11
  • 2
    Above your php code, add `ini_set('display_errors', 1);` and `error_reporting(E_ALL);` – Karlo Kokkak May 28 '18 at 05:13
  • @KarloKokkak: This is the error I get after adding ini_set('display_errors', 1); and error_reporting(E_ALL); Warning: Cannot modify header information - headers already sent by (output started at /home/staging/public_html/average.php:3) in /home/staging/public_html/average.php on line 34 – Vinay Sharma May 28 '18 at 05:23
  • again "Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP." http://php.net/manual/en/function.header.php –  May 28 '18 at 05:24
  • 1
    There you go, output started at line #3. Are you sure what you've posted is the actual PHP script? Line #34 doesn't have a call to `header` so I'd say you have extra code above this that you have not shown (at least 2 lines) – Phil May 28 '18 at 05:24
  • @Phil: Thanks for your response. I'm actually not sure. this is me first time trying something with PHP looking at the tutorials. And that's it, that's all that is in the file. – Vinay Sharma May 28 '18 at 05:27
  • 1
    @phil, there were two blank lines, which I deleted and it works! Thank you ! – Vinay Sharma May 28 '18 at 05:29

0 Answers0