繁体中文
设为首页
加入收藏
当前位置:PHP技术首页 >> PHP基础 >> 关于使用 session_start 出现的 headers already sent错误的解释

关于使用 session_start 出现的 headers already sent错误的解释

2005-02-15 08:00:00  作者:  来源:互联网  浏览次数:0  文字大小:【】【】【
简介:请看详细的错误程序和输出结果 输出为 testing ... Warning: Cannot send session cookie - headers already sent by (output started at F:PHP2000test.PHP:2) in F:PHP2000test.PHP on line 4 Warning: Cannot...

请看详细的错误程序和输出结果

输出为

testing ...

Warning: Cannot send session cookie - headers already sent by (output started at F:PHP2000test.PHP:2) in F:PHP2000test.PHP on line 4

Warning: Cannot send session cache limiter - headers already sent (output started at F:PHP2000test.PHP:2) in F:PHP2000test.PHP on line 4

分析:

主要原因,PHP.ini里有关于session 的定义,默认是使用 cookie

[session]

session.use_cookies = 1 ; whether to use cookies

这句表明使用 cookies 存储session 而 cookies的设置必须在正式 htm 之前,也就是只能在 header 里面才行,所以造成这个错误的发生

我们修改程序为

同样错误,因为 echo 已经输出了

我们修改程序为

运行正确表明在session_start的前面可以有计算语句,但是不能有输出语句

我尝试过修改

session.use_cookies = 0 ; whether to use cookies

但是没有成功,希望知道答案的朋友通知我,如何去掉cookie方式的 session

责任编辑:admin
相关文章