0

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();

?>
  • check `/Users/[username]/Sites/application/Core/users.php:3` is it echoing anything? even a blank space outside the `` is considered output – bansi Sep 04 '14 at 16:26

1 Answers1

1

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.