【问题标题】:session_start headers already sentsession_start 标头已发送
【发布时间】:2013-10-10 08:49:02
【问题描述】:

我遇到了一个问题,尽管我正在寻找答案,但我仍然无法解决。 是index.php的代码:

<?php
session_start();
?>
<html>
<head>
<title>Elektromechanika Pojazdowa</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
</head>
<body bgcolor="#170266">
    <center>
        <div id="naglowek">ELEKTROMECHANIKA POJAZDOWA</div>
        <div id="menu">
            <table width="100%">
                <tr>
                    <td width="50%">
                        <a class="menu" href="index.php?p=main">Strona Główna</a>
                    </td>
                    <td width="50%">
                        <a class="menu" href="index.php?p=contact">Kontakt</a>
                    </td>
                </tr>
            </table>
        </div>
    </center>
    <?php
        $p = $_GET['p'];
        if(!empty($p))
        include("$p".'.php');
        else
        include('main.php');
    ?>
    <div id="stopka">
        <center>
            <table>
                <tr>
                    <td width="30%">
            <center><img src="img/bendiks.jpg"></center>
                    </td>
                    <td width="30%">
            <center><img src="img/magneti marelli.jpg" width="300px"     height="170px"></center>
                    </td>
                    <td width="30%">
            <center><img src="img/bosch.jpeg"></center>
                    </td>
                </tr>
            </table>
        </center>
    </div>
    <div id="link">
        <a class="admin" href="index.php?p=admin">Panel adminitracyjny</a>
    </div>

</body>

我无法让它工作,因为我收到错误:

Warning: session_start() [function.session-start]: Cannot send session cookie - 
headers already sent by (output started at D:\Program Files\WebServ\httpd-users\dla 
Gabi\index.php:1) in D:\Program Files\WebServ\httpd-users\dla Gabi\index.php on line 2

我尝试使用ob_start();,但它不起作用。我不明白为什么会出现问题,因为session_start(); 是第一个函数,甚至放在任何 html 代码之前..

【问题讨论】:

  • Headers already sent by PHP 的可能重复项
  • 你看到右边的相关栏了吗?
  • 我在相关主题中寻找答案,但没有找到帮助:(我必须以 UTF-8 编码保存文件,这是可能的问题.. 那么有什么方法可以将文件保存在UTF-8编码能解决这个问题吗?
  • 好的,我发现我需要在每次保存后对文件进行十六进制编辑并删除前 3 个不可见的数字。但是有没有办法永久地做到这一点?
  • @ArkadiuszGaller 使用其他文本编辑器。

标签: session header


【解决方案1】:
Enable ob_start in php.ini file
<?php
session_start();
ini_set("ob_start","On");

?>

【讨论】:

  • 我可以在我自己的 PC 上完成,但不幸的是,在外部主机上这是不可能的 :( 如果你的意思是在文件 index.php 中这样做(就像你写的那样) - 它不会工作,ob_start 被此错误忽略
  • 在 php.ini 中找到 ob_start ,如果 ob_start off 意味着你会开启
  • 但我无法访问外部托管服务器上的 php.ini,这就是问题
  • 好的。 ob_start();错误报告(E_ALL|E_STRICT); ini_set('display_errors', 1);
【解决方案2】:

要访问外部托管服务器上的 php.ini,我认为您需要设置一个虚拟专用服务器 (VPS)。至少从我自己在托管服务器上缺少自定义 php.ini 文件时遇到的问题来看,我们需要一个 VPS 才能将我们自己的 ini 文件用于 php 协议。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-14
    • 1970-01-01
    • 2017-08-29
    • 2014-06-24
    • 2016-05-28
    • 2014-06-04
    • 2018-01-29
    • 1970-01-01
    相关资源
    最近更新 更多