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>

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.