SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Error: Cannot modify header information

    I just started receiving a "Cannot modify header information" error. This was working yesterday, I swear. Even worse, I hadn't touched anything today but the CSS when I first saw this.

    I've checked the usual things (flushing the buffer, ensuring no white space outside of the start / end tags, ensuring the site hasn't been tampered with) to no avail.

    Clearly, I'm doing something really wrong here; I use my half-assed approach with other sites (other servers), so if I can learn the right way to do this, I'll update those as well, I promise.

    Anyhow, the bit that causes the issue is where I modify the header:

    Code:
    <?php
    
    // NOTE: the presence of any of the below lines setting header information trigger this error;
    //
    // Implicitly permit the browser to cache the page;
    header("Cache-Control: must-revalidate");
    
    // Set header expiration date;
    $offset = 60 * 60; // SET FAR FUTURE FOR LIVE SITE
    $ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
    
    // Set header compact privacy policy;
    header("P3P: CP=\"ALL DSP COR LAW CURa ADMo DEVo TAIo PSAa PSDa IVAi IVDi CONi HISi OTPi OUR DELo SAMi IND PHY ONL UNI PUR FIN COM NAV INT DEM STA PRE LOC\", policyref=\"/w3c/p3p.xml\"");
    
    // Output header;
    header($ExpStr);
    
    ?>
    And I call this at the very top with:

    Code:
    <?php include($svr . '/inc/hdr.php'); ?>
    And the initial header feed, if that helps:

    Code:
    GET /sec/abt/ HTTP/1.1
    Host: newsite.mydomain.com
    User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language: en-us,en;q=0.5
    Accept-Encoding: gzip,deflate
    Accept-Charset: UTF-8,*
    Keep-Alive: 300
    Connection: keep-alive
    Referer: http://newsite.mydomain.com/sec/loc/
    Cookie: __utma=20390567.3086974982699465000.1240592394.1240592394.1240592394.1; __utmz=20390567.1240592394.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
    Cache-Control: max-age=0
    
    HTTP/1.x 200 OK
    Date: Tue, 12 May 2009 20:16:48 GMT
    Server: Apache/1.3.41 (Unix) mod_fastcgi/2.4.6 mod_log_bytes/1.2 mod_bwlimited/1.4 mod_auth_passthrough/1.8 FrontPage/5.0.2.2635 mod_ssl/2.8.31 OpenSSL/0.9.7a
    X-Powered-By: PHP/4.4.9
    Keep-Alive: timeout=5, max=150
    Connection: Keep-Alive
    Transfer-Encoding: chunked
    Content-Type: text/html; charset=UTF-8
    Content-Language: en-US

    Thanks!

    TaliaJ

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    right click > view html source. You will probably see the offending text or whitespace. It will be immediately before the php error message text.

    Also, the error message almost certainly tells you where the offending output started at, including which file and which line number.

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, no, there's no whitespace. But I've found a fix in the past couple of minutes.

    I've discovered that if I save the file in ANSI instead of UTF-8, the problem disappears. I'm not sure why this works, only that it does...if you or someone else knows, I would be interested to hear the explanation.

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://en.wikipedia.org/wiki/Byte-order_mark

    php just sees the character as data that it should output.

    You could still save the file as utf8, just without the BOM.

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! I'll read up on it.

    I just upgraded my text editor, and apparently it unchecked that option in the process...never thought the upgrade might be the issue. I think I was busy following TaliaJ's First Rule of Inept Problem Solving: Ignore the Obvious.

    D'oh.

    TaliaJ


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •