tags:

views:

69

answers:

4

I have a bizarre issue going on with my dev server. Just a few hours ago PHP session just totally quit working. Every single file (hundreds) started showing errors like below, about session cookies not being written. I cannot figure out what the problem is, what cause this to just start happening, before everything worked and I haven't even made any changes. Worse of all, I cannot get it working. I tried different browsers, rebooting my server, rebooting my PC even. Nothing helps, any ideas what I can do? This is really crazy

Please note I do not have any white space or anything printing to screen before calling session_start() either

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

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 test

As I mentioned, this happens on EVERY file of my site now, even simple files. The error I posted is from a file as simple as this...

<?PHP
session_start();

$_SESSION['test'] = 'test';
echo 
$_SESSION['test'];
?>
+1  A: 

Something is getting outputed in line 1 of C:\webserver\htdocs\friendproject2\labs\2.php.

Also, where did that test came from?


Seems like the issue was the file encoding, you should always use UTF-8 no BOM as the prefered encoding for your .php files, code editors such as Intype let you easily specify this (UTF-8 Plain).

alt text


You should also read The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!) by Joel Spolsky.

Alix Axel
I just updated my post with the actual code from that page. The test is from the session variable, session work on a page if I set them on that page, just it wont send the cookie and is giving ther warning messages
jasondavis
UTF-* with no BOM is a partial solution but PHP expects its input in ASCII
symcbean
A: 

You mention that you don't have any white space or anything else printing to screen before your sesssion_start() call. Have you verified but just hitting a file with the following:

<?php

session_start();
echo "Hello World";

?>

It looks like 2.php is outputting something. I would double check that file.

sberry2A
I just updated my post
jasondavis
A: 

If the start_session() is in an include file check to make sure that you include that file BEFORE you output anything to the page. That is why it is saying the headers were already sent. I have had this issue before if the start_session() is not the very first thing.

Josh Curren
A: 

With no changes to the code and multiple pages affected, my first port of call would be to check if the webserver config (or php.ini or .htaccess) has had an auto-prepend added.

This would cause sberry2A's example code to fail. If sberry2A's code works, then check for some dodgy chars in a common include file.

C.

symcbean