4

i have some Problems with session_start();

I know that nothing should be outputted before the session_start(); statement

But i can't find the Problem in my Script

index.php:

<?php session_start();
include('functions.php');
if(!is_logged_in(session_id())){
    include('form.php');
}else{
?>
<html>
<head>
<title></title>
</head>
<body>
</body>
</html>
<?php
}
?>

But i always geh following Error:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\fertige_scan\index.php:1) in C:\xampp\htdocs\fertige_scan\index.php on line 1

I hope you can help me :)

Jings
  • 8,360
  • 3
  • 18
  • 17

3 Answers3

7

Make sure you save your file without BOM if saving them in UTF8

Capsule
  • 6,118
  • 1
  • 20
  • 27
5

Make sure your file is saved as ANSI format not UTF-8 format.

Spidy
  • 39,723
  • 15
  • 65
  • 83
  • 2
    The problem with UTF8 files is the BOM, not the encoding itself. Sometimes you don't have a choice, you need UTF8. – Capsule Feb 23 '11 at 23:21
  • Damn, thank you very much. I saved it in UTF-8 Format and now i saved it as ANSI and everything works fine :) – Jings Feb 23 '11 at 23:21
  • 1
    Because you were saving them with a BOM... I'm sorry but this is not an acceptable answer. – Capsule Feb 23 '11 at 23:22
  • Yes...now i saved it as UTF-8 without BOM and everything works great. – Jings Feb 23 '11 at 23:24
  • I ran into the same problem just now, and while _of course_ the solution is to save without BOM, I do wonder **why** PHP files can't have BOMs. It feels like a misconfiguration error somewhere. More so because I don't have the problem on my localhost; the problem only occurs when I run them from an external server. – Mr Lister May 19 '14 at 10:00
2

Assuming you have removed any extra characters after <? and before ?>, and that session_start(); is the first statement, you can try to change the file encoding to ANSI or UTF-8 without BOM, as suggested in session_start's PHP documentation.

elitalon
  • 9,191
  • 10
  • 50
  • 86