I have a CI application that has an auth controller and switchuser function in it. Basically, all this is done by the identifier from the URI, gets some user data from the identifier, assigns some session data, and then loads the view.
function switch_user(){ if(!$this->auth_lib->is_admin()){ $this->session->set_flashdata('status', 'You need to be an administrator to access this page.'); redirect('auth/login'); } if($id = $this->uri->segment(3)): $this->load->model('auth_model', 'auth'); $username = $this->auth->get_username($id)->account_name; $this->session->set_userdata(array('at_id' => $id, 'username' => $username)); $this->session->set_flashdata('status','User switched.'); endif; $this->load->model('clients_model', 'clients'); $data['users'] = $this->clients->get_at_clients(); $this->load->view('auth/switch', $data); }
I get the following error:
Message: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\cp\application\controllers\auth.php:130)
Line 130 is $ username = $ this-> auth-> get_username ($ id) -> name_name;
Here is the model function:
function get_username($at_id){ $portal = $this->load->database('warehouse', TRUE); $portal->select('account_name'); $portal->where('account_id', $at_id); $portal->from('wh_account'); $query = $portal->get()->result(); return $query[0]; }
I do not understand what's going on. When I run the code locally, I do not get an error. But when I run it remotely, then through the Internet I get a header error.
Can someone help identify the problem?
Thanks,
Billy
UPDATE
I really put var_dump around $ username = $ this-> auth-> get_username ($ id) โ account_name; which caused the error. I don't know why, though :(