1
<?php
   session_start();
   $_SESSION['start']=1;

   echo $_SESSION['start'];
?>

Output in FF:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at .../test.php:1) in.../test.php on line 10

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent by (output started at .../test.php:1) in.../test.php on line 10

kapa
  • 77,694
  • 21
  • 158
  • 175
Joseph
  • 1,734
  • 6
  • 29
  • 51

4 Answers4

8

If you have saved your file in UTF-8 format, be sure to check if it is UTF-8 without BOM.

kapa
  • 77,694
  • 21
  • 158
  • 175
  • Good call. I bet you're right. I first learned about the [byte order mark](http://en.wikipedia.org/wiki/Byte_order_mark) when I opened a script in nano and it had a strange character at the beginning. – Wiseguy Apr 22 '11 at 18:09
  • I resaved my file in UTF-8 no BOM but it didnt solve it. I remember I had this prob before and it sure sound like it. Do I have to change anything else or should the resave solve it? How about doctype, mysql connection etc? Or is it simply something else? – Joseph Apr 22 '11 at 18:42
  • resaving solved it! Still, do I need to change anything else or does the utf8 no bom only apply to the encoding the file is saved as? – Joseph Apr 22 '11 at 18:49
  • Happy to hear it solved it. If you want to use UTF-8, be sure to apply it to META content-type, php header Content-type, MySQL connection, collation in your database and tables (and the encoding of your PHP files if you want to use UTF-8 constants). And anything I can't think of when I'm drunk. – kapa Apr 22 '11 at 23:51
  • This one saved my bacon! – earachefl May 17 '12 at 00:35
0

Changed encoding from UTF8 to ANSI, then saved the file and the error went away.

Andrew
  • 21
  • 2
0

Did you include this file from any other file? If so, then did those files echo/output anything?

The HTTP header that includes cookies must be outputted before the body (the HTML, usually).

Tower
  • 98,741
  • 129
  • 357
  • 507
0

Along with rFactor's response, check that you do not have any white space at the top of the PHP file (e.g. a space or a period).

Prisoner
  • 27,391
  • 11
  • 73
  • 102