session_start();报错问题

Cyber_Try 2014-03-06 12:14:21
test.php文件内容
<?php
include('site_test.php');
?>

site_test.php文件内容
<?php
session_start();
header('Content-Type: text/html; charset=utf-8');
?>

当打开test.php时报以下错误,弄了很久也弄不明白,不知为什么?


Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/cybertry/public_html/idearforyou.com/site_test.php:1) in /home/cybertry/public_html/idearforyou.com/site_test.php on line 2

Warning: Cannot modify header information - headers already sent by (output started at /home/cybertry/public_html/idearforyou.com/site_test.php:1) in /home/cybertry/public_html/idearforyou.com/site_test.php on line 3
...全文
242 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2014-03-06
  • 打赏
  • 举报
回复
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/cybertry/public_html/idearforyou.com/site_test.php:1) in /home/cybertry/public_html/idearforyou.com/site_test.php on line 2 是说:在 site_test.php 的第二行执行 session_start(); 时,发现 site_test.php 的第一行有输出 显然在 site_test.php 的 <?php 前有空格或者是 site_test.php 文件有 BOM 头
Cyber_Try 2014-03-06
  • 打赏
  • 举报
回复
而且我在本机电脑测试没有问题,就是上传到服务器后才有这个问题的。
一起混吧 2014-03-06
  • 打赏
  • 举报
回复
site_test.php 是什么编码,如果是utf-8编码,确认没有bom头。
Cyber_Try 2014-03-06
  • 打赏
  • 举报
回复
但现在session_start();前面没有输出啊,想不明白, 就是在包含文件里是这样,如果直接写在test.php里就没有问题。 难道session_start();不能包含在文件里吗?
一起混吧 2014-03-06
  • 打赏
  • 举报
回复
检查site_test.php 中<?php 前面是否有空格或空行
Hx_Moon_ 2014-03-06
  • 打赏
  • 举报
回复
session_start();前面不能有输出
answer3 2014-03-06
  • 打赏
  • 举报
回复
看看。。。。。
Cyber_Try 2014-03-06
  • 打赏
  • 举报
回复
查过了,确实是BOM头的问题,用DR另存为不包含BOM头的就正常了,谢谢大家。

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧