0

I recently uploaded my new files for my website and the header(location) call is not working. this is the error code displayed: "Warning: Cannot modify header information - headers already sent by (output started at /home/content/29/11516329/html/discount/truth.php:12) in /home/content/29/11516329/html/discount/truth.php on line 18"

here is the code I am using:

    <?php
    ob_start();

    $code = $_POST['code'];
    $secret=("abcdefg");
    if ($code == $secret)
       {
       header('Location:output.php');
       }
    else
       {
       echo "wrong code";
       }

    ob_end_flush();
    ?>

this was working for me on my local host but for some reason once it was uploaded it wouldnt work anymore. any suggestions on how to fix it?

  • 1
    check out http://stackoverflow.com/questions/8028957/headers-already-sent-by-php/8028987#8028987 – Ido Sarig Oct 05 '13 at 02:00
  • SO has around 1 million answers to this question, just like the one mentioned above. I fail to believe that this did not come up in search. https://www.google.com/?gws_rd=cr&ei=xXpPUtHcC6q44ASnj4GgAQ#q=site:stackoverflow.com+headers+already+sent – Hanky Panky Oct 05 '13 at 02:34
  • it did its just I tried the answers suggested in similar questions but none of them worked. – user2758281 Oct 05 '13 at 02:35
  • Give us whole `truth.php` file – Michael Sivolobov Oct 05 '13 at 08:22

1 Answers1

1

I would be repeating what has already been said numerous times on StackOverflow. The PHP header() function cannot be used if anything is output to the browser before the header function.

An alternative to the header() is the HTML meta refresh.

<?php
echo '<meta http-equiv="refresh" content="0; output.php">';
?>

Note: The use of the meta refresh is discouraged by W3C but then, it is the only alternative if you do not want to play around with Javascript too much.

Ankur Gupta
  • 707
  • 1
  • 9
  • 20