Results 1 to 3 of 3

Thread: Bypass the "warning: Cannot modify header information"?

  1. #1
    Join Date
    Nov 2010

    Bypass the "warning: Cannot modify header information"?

    I am tired of getting this message. Its telling me the output is from another page that is being used in +50 other pages without issue.

    Is it possible to configure PHP.ini to ignore this and simple redirect the page? PHP programmers dropped the ball here I think, because obviously I do not care about output header if I am trying to change the page...

    edit: Yep, nonsense as usual. This time it was one of my many new javascript files. The weird part was even if I wiped out all code in that JS file but kept the external script tag with its "src" it would still give me this header error. So I just moved this SINGLE js file to the bottom of my page.
    Last edited by ZeratulsDomain; 05-29-2012 at 09:20 PM.

  2. #2
    Join Date
    Mar 2011
    No. You can't bypass this issue with php.ini. Once PHP has sent any data to the user, the server response headers will have been sent and you can't use the header() function afterwards. You can often work around it by adding ob_start() to the beginning of your scripts to buffer the output, but you have to be sure to flush the buffer when you're ready for the user to start receiving data.
    Rick Trethewey
    Rainbo Design

  3. #3
    Join Date
    May 2012
    Yes you can get around it by enabling output buffering in the PHP.INI file. This sends all output from print, and so forth to the buffer... meaning header() can then modify the headers and then flush the whole buffer sending everything in the correct order to the browser (regardless of when you use header() in the script). It's also technically correct so it wont produce "suppressed" errors either

    Set output_buffering = On in php.ini and restart the server.

    When the script finishes it will automatically flush the buffer so it goes to the browser. Meaning you shouldn't have anything else to do.

    You might also want to use gzip compression since you are buffering the output... will reduce the pages download times but don't set the compression to low or to high else it will use more CPU resources than needed, or not compress it enough to be worth while find the sweet spot in the middle somewhere...

    Kind regards,

    P.S. If you do header() redirects, remember to call die() or exit() straight after

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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