Loading session class triggers header error

#3
[eluser]hermes1986[/eluser]
Hello, i'm new to this forum, and i am new to codeigniter..i have the same problem, and i got this message appear

Code:
A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\noodletrial\application\controllers\noodlehome_ctrl.php:34)

Filename: libraries/Session.php

Line Number: 671

the message appear after i put a some session syntax in my model file, here is my model file
Code:
<?php
class Users_Model extends CI_Model
{
    function _required($required,$data)
    {
        foreach ($required as $fields)
            if(!isset($data[$fields])) return false;
            
            return true;
    }
    
    function _default($default,$options)
    {
        return array_merge($default,$options);
    }

    function AddUsers ($options=array())
    {
        if (!$this->_required(array('UserId','UserName','UserEmail','UserPassword','UserStatus'),$options))
        return false;
        
        $options=$this->_default(array('UserStatus','A'),$options);
        
        $this->db->insert('users',$options);
        
        return $this->db->insert_id();
    }
    
    function UpdateUsers($options=array())
    {
        if (!$this->_required(array('UserId'),$options))
        return false;
        
        if (isset($options['UserName']))
            $this->db->set('UserName',$options['UserName']);
            
        if (isset($options['UserEmail']))
            $this->db->set('UserEmail',$options['UserEmail']);
            
        if (isset($options['UserPassword']))
            $this->db->set('UserPassword',md5($options['UserPassword']));
            
        if (isset($options['UserStatus']))
        $this->db->set('UserStatus',$options['UserStatus']);
            
        return $this->db->affected_rows();
    }
    
    function GetUsers($options=array())
    {
        if(isset($options['UserId']))
            $this->db->where('UserId',$options['UserId']);
            
        if(isset($options['UserName']))
            $this->db->where('UserName',$options['UserName']);
            
        if(isset($options['UserEmail']))
            $this->db->where('UserEmail',$options['UserEmail']);
            
        if(isset($options['UserPassword']))
            $this->db->where('UserPassword',$options['UserPassword']);
            
        if(isset($options['UserStatus']))
            $this->db->where('UserStatus',$options['UserStatus']);
            
        if(isset($options['limit'])&& isset($options['offset']))
            $this->db->limit($options['limit'],$options['offset']);
        else if(isset($options['limit']))
            $this->db->limit($options['limit']);
            
        if(isset($options['sortBy'])&& isset($options['sortDir']))
            $this->db->order_by($options['sortBy'],$options['sortDir']);
            
        $query=$this->db->get("users");
        
        if(isset($options['UserId'])||isset($options['UserEmail']))
            return $query->row(0);
        
        return $query->result();
        
    }
    
    function Login($options=array())
    {
    
        if (!$this->_required(array('UserEmail','UserPassword'),$options))
        return false;
        
        $user=$this->GetUsers(array('UserEmail'=>$options['UserEmail'],'UserPassword'=>md5($options['UserPassword'])));
        
        if(!$user) return false;
      
        $this->session->set_userdata('UserEmail',$user->UserEmail);
        $this->session->set_userdata('UserId',$user->UserId);
      
        return true;
            
    }
}

and here is my controller file which calls up to the model
Code:
<?php
class NoodleHome_Ctrl extends CI_Controller {


    function __construct()
    {
        parent::__construct();
        $this->load->model('users_model');
    }
    
    function Login()
    {
    
        $this->form_validation->set_rules('UserEmail','email','trim|required|valid_email|callback__check_login');
        $this->form_validation->set_rules('UserPassword','password','trim|required');
        
        if ($this->form_validation->run())
        {
            echo "You have successfully logged in..";
                   if($this->users_model->Login(array('UserEmail'=>$this->input->post('UserEmail'),'UserPassword'=>$this->input->post('UserPassword'))))
            {
                redirect('dashboard');
            }
            else
            {
                redirect('noodlehome_ctrl/login');
            }
            
            $this->load->view('noodlehome/login_view');
        }
    }
    
    function index()
    {
        $this->load->view('noodlehome/login_view');
    }
    
    function _check_login($userEmail)
    {
        if($this->input->post('UserPassword'))
        {
            $user=$this->users_model->GetUsers(array('UserEmail'=>$userEmail,'UserPassword'=>md5($this->input->post('UserPassword'))));
            if($user) return true;
        }
        $this->form_validation->set_message('_check_login','Your Username and Password combination is invalid');
        return false;
    }
    
}

and i found the problem in the model is :
$this->session->set_userdata('UserEmail',$user->UserEmail);
$this->session->set_userdata('UserId',$user->UserId);

and the problem in the controller is :
redirect('dashboard');

please give any help...and thx before

regards,

hermes


Messages In This Thread
Loading session class triggers header error - by El Forum - 05-06-2011, 04:14 PM
Loading session class triggers header error - by El Forum - 05-06-2011, 11:30 PM
Loading session class triggers header error - by El Forum - 05-10-2011, 10:38 AM
Loading session class triggers header error - by El Forum - 05-10-2011, 10:58 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.