PHP Session Cookies 仅在我的服务器上停止工作 [英] PHP Session Cookies stopped working on my server ONLY

查看:42
本文介绍了PHP Session Cookies 仅在我的服务器上停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的开发服务器出现了一个奇怪的问题.就在几个小时前,PHP 会话完全停止工作.每个文件(数百个)都开始显示如下错误,关于没有写入会话 cookie.在一切正常之前,我无法弄清楚问题是什么,是什么导致这种情况开始发生,我什至没有进行任何更改.更糟糕的是,我无法让它工作.我尝试了不同的浏览器,重新启动了我的服务器,甚至重新启动了我的 PC.没有任何帮助,任何想法我能做什么?这真的太疯狂了

请注意,在调用 session_start() 之前,我没有任何空白或任何打印到屏幕的内容

<块引用>

警告:session_start()[function.session-start]:无法发送会话 cookie - 标头已发送by(输出开始于C:\webserver\htdocs\friendproject2\labs\2.php:1)在C:\webserver\htdocs\friendproject2\labs\2.php第 3 行

警告:session_start()[function.session-start]:无法发送会话缓存限制器 - 标头已经发送(输出开始于C:\webserver\htdocs\friendproject2\labs\2.php:1)在C:\webserver\htdocs\friendproject2\labs\2.php上线3测试

正如我所提到的,这种情况现在发生在我网站的每个文件上,即使是简单的文件.我发布的错误来自一个像这样简单的文件......

解决方案

C:\webserver\htdocs\friendproject2\labs\2.php 的第 1 行输出了一些内容.

还有,那个test是从哪里来的?

<小时>

问题似乎出在文件编码上,您应该始终使用 UTF-8 no BOM 作为 .php 文件的首选编码,代码编辑器例如

<小时>

您还应该阅读 每个软件开发人员绝对必须知道的绝对最低要求Unicode 和字符集(没有借口!) 作者:Joel Spolsky.

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'];
?>

解决方案

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


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

这篇关于PHP Session Cookies 仅在我的服务器上停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆