PHP头/会话问题


PHP Header / Session problems

有点长的问题。我最近将我的开发人员网站移到web服务器上进行进一步测试。。在移动之前,它100%完美地工作。除了任何涉及标头的功能外,大多数功能都能正常工作。。

我已经将ob_start/flash添加到了所有使用标头的位置。。我检查了我是否在所有页面的开头调用了session_start(除非设置)。玩了很多

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

我的index.php(我已经尝试了各种方法)=

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

我检查了一下会话是否开始,但什么也没发生。更不用说我的登录脚本可以工作并设置所有$_Session变量,然后在刷新时它们就会消失。

有什么想法吗?我检查了我在header/config中发送的内容,我甚至没有使用"header Location"doo-dah

:)

正如错误消息告诉的那样,在调用session_start之前已经有一个输出。因为这个函数修改了头信息,所以之前不能进行任何输出。看看这个很棒的答案,了解原因。

所以,改变这个:

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

到此

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

也许您还需要在doctype HTML标记之前包含lan-config.phplan-header.php,这取决于您在这些文件中所做的操作。