raksmart活动促销

分享

写回答

发帖

[提问] 有人用DEDE CMS的吗?我升了PHP版本后报错

国外虚拟主机 国外虚拟主机 4598 人阅读 | 7 人回复

发表于 2008-6-24 21:49:08 | 显示全部楼层 |阅读模式

有人用DEDE CMS的吗?

我把php版本升到5.0后进后台就报错了。如下

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /xxxxxxxxxxxxxx/dede/config.php:5) in /xxxxxxxxx/include/inc_userlogin.php on line 3

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /xxxxxxxxxxxxxx/dede/config.php:5) in /xxxxxxxxx/include/inc_userlogin.php on line 3

Warning: Cannot modify header information - headers already sent by (output started at /xxxxxxxxxxxxxx/dede/config.php:5) in /xxxxxxxxxxxxxx/dede/config.php on line 9

Warning: Cannot modify header information - headers already sent by (output started at /xxxxxxxxxxxxxx/dede/config.php:5) in /xxxxxxxxxxxxxx/dede/config.php on line 24

回答|共 7 个

phpcms

发表于 2008-6-28 11:09:18 | 显示全部楼层

用dede,最怕这样的提示,小bug不断

一路同行

发表于 2008-6-28 11:59:09 | 显示全部楼层

DEDE cms 兼容性不太好

一路同行

发表于 2008-6-28 11:59:39 | 显示全部楼层

建议去DEDE cms官网论坛看看

strategy

发表于 2008-7-19 15:18:52 | 显示全部楼层

我的也不敢升级,怕出错

ifengshen

发表于 2008-10-12 20:51:48 | 显示全部楼层

dedecms兼容性不好?哈哈 天大的笑话
RAKSmart

008

发表于 2008-10-13 18:35:32 | 显示全部楼层

写程序的时候好像碰到过这个问题。。不知道是不是。。。

Warning: Cannot modify header information - headers already sent by (output started at /xxxxxxxxxxxxxx/dede/config.php:5) in /xxxxxxxxxxxxxx/dede/config.php on line 9

Warning: Cannot modify header information - headers already sent by (output started at /xxxxxxxxxxxxxx/dede/config.php:5) in /xxxxxxxxxxxxxx/dede/config.php on line 24

看看这2个页面或CONFIG.php开始部分有没有回车。空格啥的..至少我是那样解决的

不要在使用上面的函数前有任何文字,空行,回车,空格等

[ 本帖最后由 008 于 2008-10-13 06:37 PM 编辑 ]

008

发表于 2008-10-13 18:36:05 | 显示全部楼层

还有个网友更详细的解释。。你也可以看看

标题:彻底杜绝warning: Cannot add header information - headers already sent in......
作者:esayr
出自:www.phpv.net-->PHP研究室


只要你写过PHP代码,相信都遇上过这个大多时候都令人莫明其妙的warning吧..今天我们就来搞定它...............

看了PHP手册,回答如下:

6. 我得到消息“Warning: Cannot send session cookie - headers already sent...”或者“Cannot add header information - headers already sent...”。

函数 header(),setcookie() 和 session 函数需要在输出流中增加头信息。但是头信息只能在其它任何输出内容之前发送。在使用这些函数前不能有任何(如 HTML)的输出。函数 headers_sent() 能够检查您的脚本是否已经发送了头信息。请参阅“输出控制函数”。

意思是:不要在使用上面的函数前有任何文字,空行,回车,空格等.但...问题是,这答案并不令人满意.



首先:这错误是怎么产生的呢?让我们来看看PHP是如何处理HTTP header输出和主体输出的。

PHP脚本开始执行时,它可以同时发送header(标题)信息和主体信息. Header信息(来自 header() 或 SetCookie() 函数)并不会立即发送,相反,它被保存到一个列表中. 这样就可以允许你修改标题信息,包括缺省的标题(例如 Content-Type 标题).但是,一旦脚本发送了任何非标题的输出(例如,使用 HTML 或 print() 调用),那么PHP就必须先发送完所有的Header,然后终止 HTTP header.而后继续发送主体数据.从这时开始,任何添加或修改Header信息的试图都是不允许的,并会发送上述的错误消息之一.

好!那我们来解决它:

笨方法:把错误警告全不显示!
掩耳盗铃之计,具体方法就不说了 ^_^#

解决方案:

1)适用于有权限编辑PHP.INI的人

打开php.ini文件(你应试比我清楚你的php.ini在哪里),找到

output_buffering =改为on或者任何数字.如果是IIS6,请一定改为ON,不然你的PHP效率会奇慢.

2)使用虚拟主机,不能编辑PHP.INI,怎么办?

简单:

在你的空间根目录下建立一个.htaccess文件,内容如下:

AllowOverride All
PHP_FLAG output_buffering On

不幸的情况是:还是不行?全部网页都不能显示啦?

那么,你可以打电话骂一通空间商,然后让他给你把apache的.htaccess AllowOverride打开

3)在PHP文件里解决

ob_start()
启用output buffering机制。 Output buffering支持多层次 -- 例如,可以多次调用 ob_start() 函数。

ob_end_flush()
发送output buffer(输出缓冲)并禁用output buffering机制。

ob_end_clean()
清除output buffer但不发送,并禁用output buffering。

ob_get_contents()
将当前的output buffer返回成一个字符串。允许你处理脚本发出的任何输出。

原理:

output_buffering被启用时,在脚本发送输出时,PHP并不发送HTTP header。相反,它将此输出通过管道(pipe)输入到动态增加的缓存中(只能在PHP 4.0中使用,它具有中央化的输出机制)。你仍然可以修改/添加header,或者设置cookie,因为header实际上并没有发送。当全部脚本终止时,PHP将自动发送HTTP header到浏览器,然后再发送输出缓冲中的内容。

转载请一定注明来自:www.phpv.net
您需要登录后才可以回帖 登录 | 注册

本版积分规则