Session cookies not being set? [FIXED]
Posted: Wed Aug 11, 2010 7:25 pm
I'm having a problem with cookies not being sent. I don't think it's that there is stuff being sent to the browser because I don't call any view scripts until after all of the logic has finished.
I have this class to manage session data:
Where I store some basic information for the user after they have logged in:
So when the user goes to login, I set _authenticated to true and call the initialize method where it should store data the session. However, when I navigate away from the page nothing is sticking and there appear to be no cookies set. All of this code is called before anything is sent to the browser. I know it's not my session handling class because I've used that code in another project with no problems. So I guess I'm glancing over something?
I have this class to manage session data:
Code: Select all
class Session {
private $_namespace;
public function __construct($namespace = '_default') {
$this->_namespace = $namespace;
}
/**
* Erase all variables in the namespace
*/
public function clear() {
unset($_SESSION[$this->_namespace]);
}
public function __set($name, $value) {
$_SESSION[$this->_namespace][$name] = $value;
}
public function __get($name) {
if(isset($_SESSION[$this->_namespace]) && array_key_exists($name, $_SESSION[$this->_namespace])) {
return $_SESSION[$this->_namespace][$name];
}
return null;
}
public function __isset($name) {
return isset($_SESSION[$this->_namespace][$name]);
}
public function __unset($name) {
unset($_SESSION[$this->_namespace][$name]);
}
};Code: Select all
class CurrentUser {
private $_data;
private $_model;
private static $_instance;
public function initialize($user = null) {
if(!$this->_initialized) {
// If the user is logged in
if($this->_authenticated == true) {
if($user != null) {
$this->_user = $user;
} else {
$user = $this->_user;
}
$this->username = $user['username'];
$this->id = $user['id'];
$this->group = $user['group'];
$this->lastSeen = $user['last_seen']; // This gets updated in the FrontController
$this->timezone = $user['timezone'];
// If it's not set, use the default
$this->theme = ($user['theme']) ? $user['theme'] : DEFAULT_THEME;
$this->dateformat = ($user['dateformat']) ? $user['dateformat'] : DEFAULT_DATE_FORMAT;
$this->timeformat = ($user['timeformat']) ? $user['timeformat'] : DEFAULT_TIME_FORMAT;
// Otherwise we set the defaults
} else {
$this->username = 'guest';
$this->id = null;
$this->group = 1;
$this->lastSeen = time();
$this->theme = DEFAULT_THEME;
$this->dateFormat = DEFAULT_DATE_FORMAT;
$this->timeFormat = DEFAULT_TIME_FORMAT;
$this->timezone = DEFAULT_TIMEZONE;
}
$this->_initialized = true;
}
}
public function __set($name, $value) {
$this->_data->$name = $value;
}
public function __isset($name) {
return isset($this->_data->$name);
}
public function __get($name) {
if(isset($this->_data->$name)) {
return $this->_data->$name;
}
return null;
}
private function __construct() {
$this->_data = new Session('current_user');
$this->_model = new Model_User();
}
};