PHP警告: session_start(): Cannot send session cache limiter - headers already sent

标签 php session

我在这里阅读了答案How to fix "Headers already sent" error in PHP但这并不能解决我的错误。

我不明白,session_start() 是我在文件中调用的第一件事,并且我使用的是没有 BOM 编码的 UTF-8。但我仍然收到这个 php 警告。

错误:

PHP Warning:  session_start(): Cannot send session cache limiter - headers already sent (output started at /home/feyzprod/public_html/nearby/register.php:1) in /home/feyzprod/public_html/nearby/register.php on line 1

我的文件编码是

Encoding is UTF-8 without BOM

代码:

<?php session_start();
    require_once('bdservice.php');
    require_once('script.php');

    $bd = new BDService();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">

<title>NearBy Me : Courtier immobiliers</title>

<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="css/ico.css" />
<link rel="stylesheet" href="https://formoid.net/forms/30/17477/formoid-default-skyblue.css" type="text/css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="https://formoid.net/lib/iframe.js"></script>
<link rel="stylesheet" href="https://formoid.net/lib/form.css" type="text/css" />

<script>

</script>

</head>

<body>
    <div class='bar'>
        <div class='header'>
            <div id='left'></div>

            <div id='right'>
                <div style='margin-top:35px;'>
                <span><a href='#'>Français</a> | <a href='#'>Anglais</a></span><br/><br/>
                <?php
                    if(isset($_SESSION['authentification']))
                    {
                        echo "<a href='profil.php'><button class=\"large green button\">Profil</button></a>";
                    }
                    else
                    {
                        echo "<a href='connexion.php'><button class=\"large green button\">Login</button></a>";
                    }
                ?>
                </div>
            </div>

            <div style='clear:both;'></div>
        </div>
    </div>

    <div class='inscription'>
        <img src='images/inscription.png' alt='inscription' title='inscription' /><br/><br/>
            <?php
                if(!isset($_POST['Valider']))
                {

最佳答案

您可能在 /home/feyzprod/public_html/nearby/register.php 的开头有一个空格或其他空白字符,在您的错误中表明它位于第 1 行。

空格将回显到输出,这意味着您不能再写入 header ,这是 PHP 希望通过 cookie 设置 session 信息的地方。

关于PHP警告: session_start(): Cannot send session cache limiter - headers already sent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23188209/

相关文章:

javascript - 如何在 header 中使用 Access-Control-Allow-Methods

php - 为什么 PDO query() 结果的键包含表名?

php - Laravel 如何在生产环境中启动服务器

iphone - 如何在应用中实现登录和注销

PHP SESSION 变量未从 MySQL 记录插入

[WebMethod(EnableSession = true)] 时 ASP.NET Web 服务非常慢

php - 在 Linux 中的 php 中显式超时文件读取 I/O 操作?

php - 如何保护具有投票功能的画廊

php - 如何检查 session 是否已启动并重定向用户?

session - 在 Sandbox paypal 环境中运行多个 WebDriver Test 实例会导致 Session 超时问题