Cannot modify header information - headers already sent

Discussion in 'PHP' started by apukumarghose, Jan 3, 2013.

  1. #1

    Hello!

    I used the following couple of lines to redirect to a page:

    header("Location:index.php?ad_detail=1&ad_id=".$adId);
    exit();

    It shows:
    Cannot modify header information - headers already sent

    Then, I used the following couple of lines
    to redirect to a page:

    header("location:index.php?contact_us=1");
    exit();

    It also shows:
    Cannot modify header information - headers already sent

    Finally, I used the following couple of lines to redirect to a page:

    header("location:index.php");
    exit();

    It also shows:
    Cannot modify header information - headers already sent


    Is there any solution?
    Please help me out ASAP
     
    apukumarghose, Jan 3, 2013 IP
  2. showdown

    showdown Active Member

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    71
    #2
    You must have no 'echo' output before header, no spaces before php tags, no html code before header sent.
     
    showdown, Jan 3, 2013 IP
  3. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #3
    
    <?php
    ob_start();
    //put the rest of your code here
    ob_end_flush();
    ?>
    
    PHP:
    will insure that no header is sent until all your code is processed.
     
    Rukbat, Jan 3, 2013 IP