tags:

views:

82

answers:

4

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

+5  A: 

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

webbiedave
@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
Syom
@Syom: See this comment -> http://stackoverflow.com/questions/1183726/headers-already-sent-in-php#comment-1005385
Billy ONeal
@webbiedave yes, i see. could you tell me how you find the same questions? i try to do that, but don't know where
Syom
+4  A: 

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
+1  A: 

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

Eli Grey
+1  A: 

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