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.

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

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化