【问题标题】:Header already sent by [duplicate][重复] 已发送标头
【发布时间】:2014-02-25 14:49:15
【问题描述】:

我刚刚切换主机。过去一切正常。我现在已经将所有文件复制到新的 ftp 服务器上,设置了数据库等。但是我在每个页面上都会收到这些消息:

警告:session_start() [function.session-start]:无法发送会话 cookie - 标头已由 /home/ 中的(输出开始于 /home/pesterlo/public_html/core/init.inc.php:15)发送pesterlo/public_html/core/init.inc.php 第 23 行

警告:session_start() [function.session-start]:无法发送会话缓存限制器 - 标头已发送(输出开始于 /home/pesterlo/public_html/core/init.inc.php:15)在 /home/ pesterlo/public_html/core/init.inc.php 第 23 行

警告:无法修改标头信息 - 标头已由 /home/pesterlo/public_html/core/init.inc.php 中的(输出开始于 /home/pesterlo/public_html/core/init.inc.php:15)发送第 36 行

这里是init.inc.php文件(-数据库连接):

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="ext/css/main.css" />
<title>PesterLog</title>
 <link rel="icon" type="image/x-icon" href="favicon.ico" />
  <link rel="shortcut icon" href="images/favicon.ico" />
    <link rel="apple-touch-icon" href="apple-touch-icon.png" />
    <link rel="apple-touch-icon" sizes="72x72" href="apple-touch-icon-72x72.png" />
    <link rel="apple-touch-icon" sizes="114x114" href="apple-touch-icon-114x114.png" />
    <script type="text/javascript" src="http://pesterlog.tk/core/pages/js/jquery_1.5.2.js"></script>
<script type="text/javascript" src="http://pesterlog.tk/core/pages/js/loaded_contents.js"></script>
    </head>

<?php
date_default_timezone_set('Europe/London');
$core_path = dirname(__FILE__);
if (empty($_GET['page']) || in_array("{$_GET['page']}.page.inc.php", scandir("{$core_path}/pages")) == false){
header('HTTP/1.1 404 Not Found');
header('Location: index.php?page=inbox');
die();
}
session_start();
echo mysql_error();

//connects to database

include("{$core_path}/inc/user.inc.php");
include("{$core_path}/inc/private_message.inc.php");

if (isset($_POST['user_name'], $_POST['user_password'])){
    if (($user_id = validate_credentials($_POST['user_name'], $_POST['user_password'])) !== false){
        $_SESSION['user_id'] = $user_id;

        header('Location: index.php?page=inbox');

        die();
    }
}

if (empty($_SESSION['user_id']) && $_GET['page'] !== 'login'){
    header('http/1.1 403 Forbidden');
    header('location: index.php?page=login');

    die();
}

$include_file = "{$core_path}/pages/{$_GET['page']}.page.inc.php";

?>

请帮帮我。

提前谢谢你

【问题讨论】:

  • 把你的PHP代码放在你的HTML之上,去掉echo mysql_error()
  • 当我这样做时,我的所有样式都丢失了,我只有一个带有警告的白页:无法修改标题信息 - 标题已发送(输出开始于 /home/pesterlo/public_html/core/ inc/private_message.inc.php:1) 在 /home/pesterlo/public_html/core/init.inc.php 第 21 行
  • @ICanHasCheezburger 谢谢,这从登录表单页面中删除了错误,但是当您登录时,它们仍然会出现
  • 你删除了所有的die()吗?
  • @ICanHasCheezburger 是的

标签: php html session header hosting


【解决方案1】:

删除 mysql_error()。使用 ob_start();在 date_default_timezone_set() 之前;

【讨论】:

  • 谢谢,这行得通,但是当它进入收件箱时我收到这条消息:页面没有正确重定向 Firefox 检测到服务器正在重定向对该地址的请求,这种方式将永远不会完成。此问题有时可能是由禁用或拒绝接受 cookie 引起的。
  • 我认为,您正在重定向到同一页面。
  • 我的意思是,您还在 index.php 页面中包含了 init.inc.php,因此只会出现此错误
  • 那么我该如何解决这些错误呢?
猜你喜欢
  • 2011-04-17
  • 1970-01-01
  • 2011-07-04
  • 2015-06-17
  • 1970-01-01
  • 1970-01-01
  • 2013-05-03
  • 2013-04-04
  • 1970-01-01
相关资源
最近更新 更多