Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am running Xampp which is a LAMP setup basicly but for windows. I have been using it for years now with no trouble and all of a sudden, all my sites pages that use PHP sessions are now giving errors like this...

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

I realize that this happens from 1 of 2 things generally.

  1. If there is any whitespace printed to screen before session_start() function is called, that can sometimes cause this to happen
  2. If there is anything printed to the screen/browser before the session_start() is called.

Now my problem is different. Before tonight, I had hundreds of files that used sessions and none of them showed any of these errors. It is not just 1 file where I am overlooking a user error, this just started affecting all my files. I have not made any changes to my computer tonight or recently that I recall either.

What could be causing this? It is driving me insane and nobody seems to know why this started happening. I think it must be server related

I can even create a file and put it into any folder of my servers web and be a simple file like this bvelow and it will still give the error I show above....

<?PHP
session_start();

$_SESSION['test'] = 'test value';

echo $_SESSION['test'];
?>
share|improve this question
    
I just tested in Firefox (I normally use Chrome) and in Firefox it shows an additional error saying cookies could not be sent –  jasondavis Jan 23 '10 at 4:11
    
I'm willing to bet that the problem is a non visible char on one of those file, 1.php or 2.php. Check the BOM on UTF8 and remove the ?> from files to see if it improves. BTW, this is NOT a session problem but a file format !!! –  Gustavo Carreno Jan 27 '10 at 17:28

1 Answer 1

up vote 1 down vote accepted

Check if all your files are saved with UTF-8 encoding. UTF-8 encoded files may include a BOM (Byte Order Mark) to tell the difference between big endian/little endian byte order. PHP does not understand BOM and when it hits that in the begining of the file, it assumes it's dealing with data and sends it off - by then it's too late to modify headers.

The solution would be to make sure you save your files as ANSI - configure your IDE/editor

Hope it helps.

EDIT:

If this is the case, you probably have a lot of files that you need converting. You can use try using this bash shell code that uses iconv to do it for you (adapted from : http://stackoverflow.com/questions/1182037/osx-change-file-encoding-iconv-recursive)

for files in /mydisk/myfolder/*.php
  do
    iconv -f UTF-8 -t ISO-8859-1 "$files" "${files%.php}"
done
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.