PHP error: Cannot modify header information


You cannot use header() once text has been output to the browser. As your header.php include presumably outputs HTML, header() cannot be used.
You can solve this in a couple ways:
  • Move the if statement above the header include (this won't work, as you've indicated in comments that header.php sets the uid session and other vital stuff).
  • Call ob_start() at the top of the script to buffer the output.

You can't issue HTTP headers after you have outputted content.

unction Redirect($url) {
        flush(); // Flush the buffer
        header("Location: $url"); // Rewrite the header
        die;
    }


function Redirect($url) {
        flush(); // Flush the buffer
        ob_flush();
        header("Location: $url"); // Rewrite the header
        die;
    }


To ensure your error reporting level is the same across environments, you can set it in your application using error_reporting() and ini_set('display_errors', 1)
Also check your .php files for any whitespace before the opening tag and after the closing tag.
In addition to the points mentioned above, ensure you are not outputting anything before the headers are set, for example the following code would produce an error similar to the one you are receiving:
echo 'Hello, World';
header('Location: http://www.somesite.com');
Related Posts:
  • php urlencode - Make a strong GET Query String  php urlencode URL-encodes a string, converting spaces into plus (+ ) signs. urlencode() makes a string safe to use as part of a URL. It does this by encoding every character within the string that may be misi… Read More
  • php-Error Control Operators PHP gives one error control operator: the at sign (@).Any error messages that might be generated by that expression will be ignored. If you have set a custom error handler function with set_error_handler() then it will s… Read More
  • Web-Based MySQL Administration Web-Based MySQL Administration At http://phpwizard.net/phpMyAdmin you will find a PHP Web application that can help you manage MySQL. It enables you to manage a MySQL database using a browser and makes administrative work… Read More
  • What Is a WAMP, MAMP, or LAMP? WAMP, MAMP, and LAMP are abbreviations for Windows, Apache, MySQL, andPHP,Mac, Apache, MySQL, and PHP, and Linux, Apache, MySQL, and PHP.These abbreviations describe a fully functioning setup used for developing dynamicInter… Read More
  • php implode array elements php implode array elements Join array elements with a string string. implode(string, arraypieces) Returns a string containing a string representation of all the array elements in the same order,  string between each e… Read More
  • php-static variables A static variable retains its value between calls to a function but is visible only within that function. IT declare a variable static with the static keyword. function test_counter ( ) { static $counter = 0; $counte… Read More
  • Drupal Bootstrap Process Drupal Bootstrap Process? Drupal bootstraps itself on every request by going through a series of bootstrap phases. These phases aredefined in bootstrap.inc and proceed. Configuration Sets global variables used throughout th… Read More
  • Php Operators PHP Operators The following table lists the operators from highest to lowest precedence. Operators A !, ~, ++, --, @ Right *, /, % Left +, -, . Left <<, >> Left <… Read More
  • Php Networking Functions There are many functions in php to convert or look up domain name, IP address, protocol, and service information. Domain name/IP address lookups and conversions gethostbynamel() gethostbyname() gethostbyaddr() … Read More
  • php best tutorial-php variables PHP automatically creates variables for all the data it receives in an HTTP request. This can include GET data, POST data, cookie data, and environment variables. The variables are either in PHP's global symbol table or … Read More
  • XMLHttpRequest-Ajax To do this, you must understand the three ways of creating an XMLHttpRequest object• IE 5: request = new ActiveXObject("Microsoft.XMLHTTP")• IE 6+: request = new ActiveXObject("Msxml2.XMLHTTP")• All others: request = new XML… Read More
  • pass information from page to page-best seo Adding information to the URL: You can add certain information to the end of the URL of the new page, and PHP puts the information into builtin arrays that you can use in the new page. This method is most appropriate when yo… Read More
  • Advanced Database Techniques PEAR DB is the database primitives shown earlier; it provides several shortcut functions for fetching result rows, as well as a unique row ID system and separate prepare/execute steps that can improve the performance of re… Read More
  • IT company in kolkata Matrix Technologies Pvt. Ltd.8/1C, Chowringhee Lane, Room No. 2E, 2nd flKolkata7000162252 8/29 Media Software61A, S.N.Roy RdKolkata70003424479580 Metalogic Systems Pvt. LtdPlot-J1/1, Block-EP and GP, Sector-V, Salt LakeK… Read More
  • PHP variable-related functions Cast a value from one type to other type:- doubleval(), intval(), strval() Set  type of a variable:- settype() Verify  the type of a variable:- is_array(), is_bool(), is_double(), is_float(), is_int(), … Read More