Yes, Notepad is one of those editors that does this (unless you save the file with an ANSI character set). Visual Studio also provides the option, but if I recall, for HTML files it defaults to Latin-1 and you have to tell it to use UTF-8 (with BOM).
Yes that's right. I had the same problem with few files created by Notepad and i was quite confuse.
My problem came from the ANSI character set UTF-8 with BOM.
After a lot of research i found this this information then i fixed the problem.
I just recreated the file with different editor and everything works fine.
I hope this information can save your time and nerves.
@Rodney: Your problem wasn't UTF-8 itself (I use it on several projects), but rather than your text editor probably included the BOM character at the beginning of the file. Since the BOM isn't part of "<?php", PHP assumes that you meant for it to be outputted to the user.
Same Problem: "Warning: session_start() [function.session-start]: Cannot ..."
I know this is an old thread but perhaps someone can help.
I have created a test file with ONLY this code:
$value = session_start();
echo "Session value = ".$value."<br>";
As suggested in this thread (or elsewhere):
1) There are no spaces, html, etc. preceding this.
2) The file is encoded in UTF-8 WITH BOM
3) I've modified my php.ini file to set: session.cache_limiter = public
And I get these errors:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\feralpots\eNorman\test.php:1) in C:\xampp\feralpots\eNorman\test.php on line 2
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\feralpots\eNorman\test.php:1) in C:\xampp\feralpots\eNorman\test.php on line 2
Session value = 1
As long as session_start is the first line it seems to work
I'm using Notepad++ and had the PHP down in the body. Once I moved it to the very first line it was fine. Even the <html> tag caused it to break if it was first. This works:
session_start(); // initialise a session - commented out as it seems to auto start
$_SESSION['counter']++; // increment a session counter
<?php echo "You have viewed this page ". $_SESSION['counter'] . " times"; ?>
Since session_start() modifies the outgoing HTTP response headers, it doesn't have to be the 'first' line of code - it just has to be called before any output (which causes the HTTP headers to be sent at that point).
Then you were doing something very, very wrong, because the call to session_start() doesn't have to be surrounded by its own set of PHP tags, nor does it need to be the first statement in the script (or even at the "beginning").
I'm getting the same error on line 1 of my code. my session starts on top and I tried saving in notepad++ in UTF without BOM. STILL no luck. this script was working, and hasn't moved servers or anything so I'm not sure what happened...could the way the file is uploaded affect it working?