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?