Warning: Cannot modify header information - headers already sent by

Discussion in 'PHP' started by jimmy4feb, Jun 12, 2010.

  1. #1
    I have just write a two line code in PHP (to test that way my "header" are not working on several pages) which is as follows:

    
    <?PHP
             header('location:welcome.php'); // This is line 2
             exit;
    ?>
    
    PHP:
    This code is working fine & this script redirecting me to "welcome.php" on my localhost (my computer) but when I upload same code to my web sever I am getting following warning:

    Warning: Cannot modify header information - headers already sent by (output started at /home/myhostname/public_html/website.com/test/test.php:1) in /home/hostname/public_html/website.com/test/test.php on line 2

    I have another web server & on that server this same script working fine too.

    So, I come to conclusion that I need to make some changes in my "ini" file so that sever can ignore all these type of warnings, but I donot know that which parameter(s) I need to change & how I can change it(them) on server.

    Another solution is that I improve my script so that it does not generate such warnings, again I donot know how I can write such script which does not generate such warnings.

    Please send me any solution to solve this problem. Any help will be appreciated.

    Thanks,

    Akash
     
    jimmy4feb, Jun 12, 2010 IP
  2. Amator

    Amator Well-Known Member

    Messages:
    1,424
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    165
    #2
    Hi Akash,
    do you have 1 or more empty spaces before the code <?php ... ?
     
    Amator, Jun 12, 2010 IP
  3. jimmy4feb

    jimmy4feb Peon

    Messages:
    56
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hello,

    Thanks for reply....

    There are no white spaces in code. same code is working perfectly on my localhost & a web server as well, but its not working the web server where I want to run it. (I have two web server accounts with two different companies for two different websites)

    I know I need to make changes in "ini" file so that server just ignore this warning... (as my one server & localhost are doing...), but I don't know where to make change in "ini" file. If have any idea please help. I am trying to solve this problem last many hours.

    Thanks once again,
     
    jimmy4feb, Jun 12, 2010 IP
  4. sudcool87

    sudcool87 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This kind of problem occurs when any empty space occurs before the starting of <?php ?> tag, or any html tag ( ie generating output) occurs before <?php header();?>
     
    sudcool87, Jun 12, 2010 IP
  5. amaroks

    amaroks Peon

    Messages:
    242
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Disable debugging and you should be fine
     
    amaroks, Jun 12, 2010 IP
  6. NoamBarz

    NoamBarz Active Member

    Messages:
    242
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #6
    Something is written to the header before the location redirect. Be sure to get rid of all chars written to the browser. Also, try using a header script with a full address "http://www.blaa".
     
    NoamBarz, Jun 13, 2010 IP