0

I am currently getting the following error using php:

Warning: session_start() [function.session-start]: 
Cannot send session cache limiter - headers already sent 
(output started at /home/paramireze/madisonh3.com/calendar.php:1)
in /home/paramireze/madisonh3.com/includes/common.php on line 5

The first line of every file is include common.php, and the first line of code in common.php is 'if(!isset($_SESSION)) {session_start();}`.

This error only occurs on calendar.php and news.php (you can see the error if you visit http://www.madisonh3.com/calendar.php). All my files are the same, which includes a common.php. After that, I will write the html tag and include the header from there.

I've read other discussions regarding session_start and all say to make sure you do not output any html before session_start. Also, if I am doing something wrong, why is it only happening to two out of my 10 files?

cdeszaq
  • 30,869
  • 25
  • 117
  • 173
paul
  • 325
  • 2
  • 15

2 Answers2

2

There is something outputting data BEFORE your session_start() command. As the session cookie is set to the HTTP header it must precede any HTML output.

The error Cannot send session cookie - headers already sent by (output started at /home/paramireze/madisonh3.com/calendar.php:1) in /home/paramireze/madisonh3.com/includes/common.php on line 5 indicates something is outputted before.

So look into your code and find what could be echoing data before your session_start().

jtheman
  • 7,421
  • 3
  • 28
  • 39
  • session_start is the first line of every file using an include – paul Mar 07 '13 at 20:00
  • No when I view your source I find `
    `before the error message...
    – jtheman Mar 07 '13 at 20:01
  • I don't, which sucks I get the following – paul Mar 07 '13 at 20:07
  • Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/paramireze/madisonh3.com/calendar.php:1) in /home/paramireze/madisonh3.com/includes/common.php on line 5
    – paul Mar 07 '13 at 20:07
  • There's no magic here. Even a whitespace or a newline before your include might cause this to happen. There IS an output made from your script(s) before the session_start() and as other script including the same file seem to work you should look into the calendar.php file. – jtheman Mar 07 '13 at 20:09
0

You should care that your editor does not store the utf-8 BOM header, this header is sometimes stored at the begin of the file with 3 bytes .

The editor will hide them, so if you are not sure if your file contains these characters, you can either use a non interpreting editor (hex editor), or this wonderful online W3C checker. The BOM header is treated as output by PHP, and this can cause nasty Cannot modify header information - headers already sent errors.

Checking your URL shows, that there is indeed such a BOM header. Have a look at the settings of your editor (IDE).

martinstoeckli
  • 23,430
  • 6
  • 56
  • 87