dragon8899
2014-09-04 16:22
浏览 29
已采纳

类会话警告php 5.4中的session_start()[重复]

This question already has an answer here:

i have issuer in my files php get in index.php messages Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /Users/[username]/Sites/application/Core/users.php:3) in /Users/[username]/Sites/application/Core/session.php on line 20

<?php
// A class to help work with Sessions
// In our case, primarily to manage logging users in and out

// Keep in mind when working with sessions that it is generally 
// inadvisable to store DB-related objects in sessions


require_once('includes/initialize.php');

class Session{


    private $logged_in=false;
    public $id;


    function __construct() {
        //@ob_start();
        session_start();
        $this->check_login();

        if($this->logged_in) {

        }else{

        }


    }


    public function is_logged_in() {
       return $this->logged_in;
     }

    public function login($username) {
     // database should find user based on username/password
         if($username){
           $this->id = $_SESSION['id'] = $username->id;
           $this->logged_in = true;
         }
    }


    public function logout() {
      unset($_SESSION['id']);
      unset($this->id);
      $this->logged_in = false;
    }



    private function check_login() {
        if(isset($_SESSION['id'])) {
          $this->id = $_SESSION['id'];
          $this->logged_in = true;
        } else {
          unset($this->id);
          $this->logged_in = false;
        }
    }
}

$session = new Session();

?>
</div>
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongsong4418 2014-09-04 16:26
    已采纳

    session_start(); has to be called before anything else. You need to take it out of your constructor and place it before your require_once statement.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题