Solution to “Cannot modify header information – headers already sent”
Sunday, November 15th, 2009Hi!
This problem seems to occur on a frequently acting basis, so I’ll try to make a summary of the several solutions you can find on the net here:
Solution nr 1: Trim whitespaces near your start-tag in php, so it looks like this:
session_start(); /* After trimming whitespace, write out your header and the rest of your code */
Solution nr 2: header() is coming after require/include
session_start(); /* Try to make requires/includes compile after header */ header("Location: http://www.yoursite.com/mypage.php"); include("helperClass.php"); //code here
3. Or the pandoras box-solution: change the coding of the current file from UTF-8!
Sometimes (I don’t know for what reason) apache can’t read UTF-8 properly and think of the start-tag as other characters.
/* #1: Open your file in a text editor (i recommend notepad++ or notepad) #2: Change the coding of the file from UTF-8 to ANSI. #3: Save and upload it to the server again. */
That’s summarises the top 3 solutions for this type of problem. There’s probably more solutions, but in order to find them, you need to dig deep into the search engines.