duanfu1873 2011-06-08 04:24
浏览 110
已采纳

session_start()[function.session-start]:无法发送会话缓存限制器

I'm getting the following warnings when trying to initiate a session:

Warning: session_start() [function.session-start]: 
Cannot send session cache limiter - headers already sent 
(output started at /www/zxq.net/l/i/b/librarymanagement/htdocs/public/admin/index.php:2) 
in /www/zxq.net/l/i/b/librarymanagement/htdocs/includes/session.php on line 9

I've made sure all white space is clear, session_start() should be the first thing being called. I don't think anything else is being sent before session_start() is called.

Here is my code:

class Session {
    private $logged_in=false;
    public $user_id;
    public $message;
    function __construct() {
        session_start();
        $this->check_message();
        $this->check_login();
        if($this->logged_in) {
        } else {
        }
    }

    public function is_logged_in() {
        return $this->logged_in;
    }
    public function login($user) {
        if($user) {
            $this->user_id = $_SESSION['user_id'] = $user;
            $this->logged_in = true;
        }
    }  
    public function logout() {
        unset($_SESSION['user_id']);
        unset($this->user_id);
        $this->logged_in = false;
    }
    public function message($msg="") {
        if(!empty($msg)) {
            $_SESSION['message'] = $msg;
        } else {
            return $this->message;
        }
    }
    private function check_login() {
        if(isset($_SESSION['user_id'])) {
            $this->user_id = $_SESSION['user_id'];
            $this->logged_in = true;
        } else {
            unset($this->user_id);
            $this->logged_in = false;
        }
    }  
    private function check_message() {
        if(isset($_SESSION['message'])) {
            $this->message = $_SESSION['message'];
            unset($_SESSION['message']);
        } else {
            $this->message = "";
        }
    }

}

Here is how it is used:

$session = new Session();
$message = $session->message();

What could be the problem?

  • 写回答

4条回答 默认 最新

  • dqgxazo4483 2011-06-08 04:32
    关注

    You're trying to send headers after the body of response or in the middle part of the body, it's not allowed in HTTP...

    the reason is if you start your code

    \s
    <?php
    

    you space is the body part of your response... and when you finish your code with

    ?>
    \s
    

    this space is output too....

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示