Can not modify header information error!

Discussion in 'PHP' started by ebusinesscenter, Nov 14, 2007.

  1. #1
    Hi
    I use a script that i need to change it's language and so i must change page charset of language.php file to utf-8.
    After this , my script dont work completly and in some page error.
    error is : cannot modify header information , it modified by language.php before!!!!
    what is problem?:confused:
     
    ebusinesscenter, Nov 14, 2007 IP
  2. live-cms_com

    live-cms_com Notable Member

    Messages:
    3,128
    Likes Received:
    112
    Best Answers:
    0
    Trophy Points:
    205
    Digital Goods:
    1
    #2
    I imagine you are doing header("Location: /index.php"); in a different file and language.php is included in this file and language echos the charset. You are not allowed to echo before calling header().
     
    live-cms_com, Nov 14, 2007 IP
  3. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #3
    Turn on output buffering. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer so you will not receive "cannot modify header information" error.

    use ob_start(); as the first line of your code and ob_end_flush(); should be last line of code in the script. you may need to change header and footer files for doing this.
     
    greatlogix, Nov 14, 2007 IP
  4. sickanimations

    sickanimations Peon

    Messages:
    137
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The error occurs because data has been sent (therefore, the header has also been sent) and you're trying to edit the header. Make sure whatever line causes the error is before any other line that creates output.
     
    sickanimations, Nov 14, 2007 IP
  5. salmanshafiq

    salmanshafiq Well-Known Member

    Messages:
    260
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    128
    #5
    Headers come before a content. if you turn off buffering and do a
    Write anything, its too late to change a header
    because they have already been sent to the client.

    and you can also use javaScript
    <script language='javaScript'>
    window.location='index.php';
    </script>
     
    salmanshafiq, Nov 14, 2007 IP
  6. nabz245

    nabz245 Well-Known Member

    Messages:
    677
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    110
    #6
    Make sure you put your header before the content.
     
    nabz245, Nov 14, 2007 IP
  7. salmanshafiq

    salmanshafiq Well-Known Member

    Messages:
    260
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    128
    #7
    use javaScript code to redirect the page if you don't want to put the header at the top

    <script language='javaScript'>
    window.location='index.php';
    </script>
     
    salmanshafiq, Nov 15, 2007 IP