我在我的文件中有发行者php获取index.php消息 警告:session_start():无法发送会话缓存限制器 - 已在/ Users / [username] / Sites / application /中发送的标头(在/Users/[username]/Sites/application/Core/users.php:3处开始输出)第20行的Core / session.php
<?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();
?>
答案 0 :(得分:1)
session_start();
。您需要将其从构造函数中取出并放在require_once
语句之前。