du77887 2013-11-23 02:42
浏览 36
已采纳

PHP标头/会话问题[重复]

This question already has an answer here:

slightly long question. I recently moved my Dev site to a web server for further testing.. and it was working 100% perfectly before the move. Most features are working except for anything involving headers..

I've added ob_start / flush to all the places I'm using headers.. and I checked that I called session_start at beginning of all pages (unless set). Played around with lot's of

things :/ But I get 1000 errors. 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /var/sites/p/******/public_html/index.php:3) in /var/sites/p/*******/public_html/index.php on line 4

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /var/sites/p/party******/public_html/index.php:3) in /var/sites/p/*******/public_html/index.php on line 4
Debug active

And my index.php (I've tried every way) =

<!DOCTYPE html>
<html lang="en">
<?php if (!isset($_SESSION)) {
  session_start();
  }
  ?>
<?php include ('lan-config.php')?>
<?php include (ABSPATH. 'lan-header.php') ?>
<?php 
  ?>
  <body>

I checked to see whether a session even starts, and nothing is happening. Not to mention my login script works and sets all the $_Session variables and then on refresh they dissapear.

Any ideas? I checked what I was sending in header / config and I don't even use the "Header Location" doo dah

:)

</div>
  • 写回答

1条回答 默认 最新

  • doubian6241 2013-11-23 02:45
    关注

    As the error message tells you, there is already an output before the call of session_start. Because this function modify header informations, you can't make any output before. Have a look at this awesome answer to understand why.

    So, change this :

    <!DOCTYPE html>
    <html lang="en">
    <?php if (!isset($_SESSION)) {
      session_start();
      }
      ?>
    <?php include ('lan-config.php')?>
    <?php include (ABSPATH. 'lan-header.php') ?>
    <?php 
      ?>
      <body>
    

    To this

    <?php 
    if (!isset($_SESSION)) {
      session_start();
      }
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <?php include ('lan-config.php')?>
    <?php include (ABSPATH. 'lan-header.php') ?>
    <?php 
      ?>
      <body>
    

    Maybe you will need to include lan-config.php and lan-header.php before the doctype HTML tag too, it depends of what you do in these files.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向