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.
I had this problem. Went through and cleaned up all spaces and lines. It still didn't work. Then I changed from UTF-8 to ASCII. Bingo! So now I'll try to use ASCII for php and UTF-8 for HTML
@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.
If you just use Notepad to write your scripts then i would highly encourage you to download Notepad++. Quite easily the best text editor for web design available. And its free!
After scratching my head with the same problem, i found that there was a new line after the closing ?> php tag in one of my include files. Like others have mentioned, this is a definite 'gotcha'
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:
<?php
$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
means that there is something in front of the session_start
2) The file is encoded in UTF-8 WITH BOM
I believe that is suppose to be without BOM. But save yourself the hassle and get anyone of the hundreds of free IDE's out there. NotePad++ is a good one to start with.
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:
<?php
session_start(); // initialise a session - commented out as it seems to auto start
$_SESSION['counter']++; // increment a session counter
?>
<html>
<head>
</head>
<body>
<?php echo "You have viewed this page ". $_SESSION['counter'] . " times"; ?>
</body>
</html>
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).
I enclosed the start_session() command in php tags at the beginning of my script and then started a new php tag for the rest of the code. This is the only solution that worked for me, as follows:
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?
Bookmarks