开发者

PHP Session Cookies stopped working on my server ONLY

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开发者_JAVA技巧\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'];
?>


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).

PHP Session Cookies stopped working on my server ONLY


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜