4

Im trying to set up a session and i am getting a header error, dispite as far as i can tell i am telling it to start the session before the header is sent. any help here would be useful.

<?php
ob_start();
session_start();
$_SESSION['active'] = 1;
ob_end_flush();
?>
<html>
<body>
2009c Christ Redeemer Catholic Church 
</body>
</html>

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/content/k/u/r/kuriomister/html/temp/church/index.php:1) in /home/content/k/u/r/kuriomister/html/temp/church/index.php on line 3

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/k/u/r/kuriomister/html/temp/church/index.php:1) in /home/content/k/u/r/kuriomister/html/temp/church/index.php on line 3

user54229
  • 53
  • 1
  • 4

2 Answers2

9

If you use UTF-8, be sure to save the file without BOM.

Gumbo
  • 643,351
  • 109
  • 780
  • 844
  • BOM = Byte Order Mark. UTF-8 = Unicode Transformation Format 8-bit encoding – Anthony Faull Jan 03 '10 at 11:04
  • I am having this exact same problem all of a sudden, sitewide on every page on my whole server. I havent even changed anything, it just started happening a few hours ago, I can evern create a new test file that uses sessions and it will give the same errors even when there is not spaces before output, any ideas how to fix? – JasonDavis Jan 23 '10 at 04:07
3

See the output: Cannot send session cookie - headers already sent by (output started at /home/content/k/u/r/kuriomister/html/temp/church/index.php:1). You seem to have some whitespace (spaces, tabs, linebreaks, ...) at the beginning of the file.

Piskvor left the building
  • 91,498
  • 46
  • 177
  • 222