How to solve -> Warning: Cannot modify header information – headers already sent by …

May 07, 2010 By: admin Category: Bugs, PHP

A common problem PHP developers may encounter while redirect a page to another is :

Warning: Cannot modify header information – headers already sent by ….

when using the code below:


header( "Location: $url" );

There are different ways to solve this problem:

Method 1

  1. Open your php.ini file. It is under the main directory of your PHP installation in Windows and
    /etc in Unix/Linux
  2. Replace
  3. output_buffering = off
    with
    output_buffering = 4096

  4. Restart your Apache server

Method 2

  1. At the start of your PHP script/page put
  2. <php? ob_start(); ?>

    This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer. Output buffers are stackable, that is, you may call ob_start() while another ob_start() is active. Just make sure that you call ob_end_flush() the appropriate number of times. If multiple output callback functions are active, output is being filtered sequentially through each of them in nesting order.

Subscribe To Site:

Leave a Reply