-1

I have a file, which starts <?php session_start();?>, and it returns an error

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp2\htdocs\index.php:1) in C:\xampp2\htdocs\index.php  on line 3

and now take a look at the moment, i can't anderstand anyway when i copy the all content of my file into another file, it start working. can somebody explain how can it happen. thanks

update

i havent't any white spaces, at least i can't see them

Itay Moav -Malimovka
  • 52,579
  • 61
  • 190
  • 278
Simon
  • 22,637
  • 36
  • 92
  • 121
  • Considering the second dupe I posted is the exact same error with similar code I highly doubt it's not a duplicate. Also, I don't understand what "hi use alert, bit I don't" is supposed to mean. – Billy ONeal Apr 08 '10 at 22:57
  • @syom: The second duplicate I posted has no white spaces either. – Billy ONeal Apr 08 '10 at 22:58
  • @Billy ONeal i can't understand why it start working when i copy the file! – Simon Apr 08 '10 at 23:00
  • @Syom: Read the answers to the second dupe I posted (looking over the first I agree it is not a duplicate) and that should fix your problem. Not all characters are visible in your file. If your editor is inserting the Byte Order Mark it will break PHP's header handling. – Billy ONeal Apr 08 '10 at 23:02

4 Answers4

5

You probably have some white-space somewhere near the top of your file.

webbiedave
  • 48,414
  • 8
  • 88
  • 101
  • @webbiedave i even try to delete all the script, exept session_start(),and it's still return the error. and i've noticed the same problem when using cookies – Simon Apr 08 '10 at 22:56
  • @Syom: See this comment -> http://stackoverflow.com/questions/1183726/headers-already-sent-in-php#comment-1005385 – Billy ONeal Apr 08 '10 at 23:00
  • @webbiedave yes, i see. could you tell me how you find the same questions? i try to do that, but don't know where – Simon Apr 08 '10 at 23:03
4

You probably have some whitespace outside your <?php tags. Any content outside is sent to the client (including spaces, tabs, newlines, and carriage returns), and once content has been sent, headers cannot be. Starting a session involves sending headers (for cookies).

Be sure to check any files that are including or requiring the file containing session_start(). The output started at C:\xampp2\htdocs\index.php:1 in your error message tells you exactly where to look (the 1 is the line number).

edit

Looking again at your error message, you're calling session_start() on line 3. So if you file begins with <?php on line 3, you've got two newlines and/or carriage returns before then. Note that these might not be visible in your text editor, based on the file encoding, operating system, etc. When you copied the code into a new file, these probably got stripped out.

keithjgrant
  • 12,421
  • 6
  • 54
  • 88
1

Make sure you're not saving the file with a byte order mark (little/big endian).

Eli Grey
  • 35,104
  • 14
  • 75
  • 93
1

check your script with notepad++ and show all character.

or you might want to delete first line and make sure <?php is at the very top.

wiiman
  • 11
  • 1