php “无法发送会话缓存限制器 - 标头已发送”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8812754/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 05:33:57  来源:igfitidea点击:

"Cannot send session cache limiter - headers already sent"

phpsession

提问by user1039878

Having a problem with sessions which is becoming very annoying. Every time I try to start a session on a particular page I get the following error:

会话问题变得非常烦人。每次我尝试在特定页面上启动会话时,都会收到以下错误:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at ............ on line 23

using this code:

使用此代码:

<?php
session_start();
if(isset($_SESSION['user']))
    {
        $user = $_SESSION['user'];
        echo "$user";
    }
else
    {
    }
?> 

Is it suggesting I've already used session_start();? Ive had a look around but nothing really clears this up for me.

是不是暗示我已经用过了session_start();?我环顾四周,但没有什么能真正为我解决这个问题。

Thanks

谢谢

回答by houbysoft

"Headers already sent" means that your PHP script already sent the HTTP headers, and as such it can't make modifications to them now.

“Headers already sent”意味着您的 PHP 脚本已经发送了 HTTP 标头,因此现在无法对其进行修改。

Check that you don't send ANY content before calling session_start. Better yet, just make session_startthe first thing you do in your PHP file (so put it at the absolute beginning, before all HTML etc).

在调用之前检查您没有发送任何内容session_start。更好的是,session_start在你的 PHP 文件中做你做的第一件事(所以把它放在绝对的开头,在所有 HTML 等之前)。