diff options
Diffstat (limited to 'application')
-rw-r--r-- | application/controllers/user.php | 1 | ||||
-rw-r--r-- | application/models/muser.php | 41 |
2 files changed, 39 insertions, 3 deletions
diff --git a/application/controllers/user.php b/application/controllers/user.php index add6e8bdc..ef79baa78 100644 --- a/application/controllers/user.php +++ b/application/controllers/user.php @@ -36,6 +36,7 @@ class User extends CI_Controller { function login() { + $this->muser->require_session(); $this->session->keep_flashdata("uri"); if ($this->input->post('process')) { diff --git a/application/models/muser.php b/application/models/muser.php index 8ec4de4c5..c29c04df6 100644 --- a/application/models/muser.php +++ b/application/models/muser.php @@ -4,18 +4,51 @@ class Muser extends CI_Model { function __construct() { parent::__construct(); - $this->load->library("session"); + + if ($this->has_session()) { + $this->session->keep_flashdata("uri"); + } + $this->load->helper("filebin"); - $this->session->keep_flashdata("uri"); + } + + function has_session() + { + // checking $this doesn't work + $CI =& get_instance(); + if (property_exists($CI, "session")) { + return true; + } + + // Only load the session class if we already have a cookie that might need to be renewed. + // Otherwise we just create lots of stale sessions. + if (isset($_COOKIE[$this->config->item("sess_cookie_name")])) { + $this->load->library("session"); + return true; + } + + return false; + } + + function require_session() + { + if (!$this->has_session()) { + $this->load->library("session"); + } } function logged_in() { - return $this->session->userdata('logged_in') == true; + if ($this->has_session()) { + return $this->session->userdata('logged_in') == true; + } + + return false; } function login($username, $password) { + $this->require_session(); $query = $this->db->query(' SELECT username, id, password FROM `users` @@ -42,6 +75,7 @@ class Muser extends CI_Model { function logout() { + $this->require_session(); $this->session->unset_userdata('logged_in'); $this->session->unset_userdata('username'); $this->session->sess_destroy(); @@ -74,6 +108,7 @@ class Muser extends CI_Model { echo "FileBin requires you to have an account, please go to the homepage for more information.\n"; exit(); } else { + $this->require_session(); if (!$this->session->userdata("flash:new:uri")) { $this->session->set_flashdata("uri", $this->uri->uri_string()); } |