频道栏目
首页 > 资讯 > Cookie&Session > 正文

关于使用session_start 出现的headers

16-01-07        来源:[db:作者]  
收藏   我要投稿

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

  1. <html> 
  2. <? 
  3. echo "testing ... "
  4. session_start(); 
  5. ?> 
  6. </html> 

输出为

  1. testing ...  
  2. Warning: Cannot send session cookie - headers already sent by (output started at F:php2000test.php:2) in F:php2000test.php on line 4 
  3. 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 里面才行,所以造成这个错误的发生,我们修改程序为:

  1. <? 
  2. echo "testing ... "
  3. session_start(); 
  4. ?> 

同样错误,因为 echo 已经输出了,我们修改程序为

  1. <? 
  2. $i=1; 
  3. session_start(); 
  4. ?> 

运行正确表明在session_start的前面可以有计算语句,但是不能有输出语句,我尝试过修改:

  1. session.use_cookies = 0 ; whether to use cookies 

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


相关TAG标签
上一篇:cookie和session 区别
下一篇:session Cannot send session cache limiter 错误提示
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站